'module' object is not callable Django

被刻印的时光 ゝ 提交于 2019-12-13 11:06:05

问题


views.py

 for user in users:
     #for profile in RegistrationProfile.objects.filter(user=user):
     #if profile.activation_key_expired():
     salt = sha_constructor(str(random())).hexdigest()[:5]
     profile.activation_key = sha_constructor(salt+user.username).hexdigest()
     user.date_joined = datetime.now()

     user.save()
     profile.save()
     #if Site._meta.installed:
     site = Site.objects.get_current()
     # else:
     site = RequestSite(request)

     profile.send_activation_email(site)

     context.update({"form" : form})
     return render_to_response("registration/registration_complete.html", context)

imports of my views:

import django.contrib.sessions
from django.core.mail import send_mail
from django.core.mail import EmailMessage
from mail_templated import EmailMessage
from django.db.models import Sum
from tinymce.widgets import TinyMCE 
from django.utils.encoding import smart_unicode
import datetime
from django.db.models import Q
from django.utils.hashcompat import sha_constructor
from registration.models import RegistrationProfile
import random
from django.contrib.sites.models import Site, RequestSite 

this is giving me error ' module' object is not callable..can anyone tell me why? plz tell me what i am missing


回答1:


I think you should check your imports. random is both a module name and a function inside a module. If you have

import random

Then you need to call random.random instead of just random.



来源:https://stackoverflow.com/questions/16230487/module-object-is-not-callable-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!