'module'对象不可调用Django [英] 'module' object is not callable Django

查看:110
本文介绍了'module'对象不可调用Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

views.py

 为用户的用户:
#for配置文件在RegistrationProfile.objects.filter(用户= user):
#if profile.activation_key_expired():
salt = sha_constructor(str(random()))hexdigest()[:5]
profile.activation_key = sha_constructor + 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)
pre>

导入我的视图:

  import django.contrib。会话
从django.core.mail导入send_mail
从django.core.mail import EmailMessage
从mail_templated import EmailMessage $ b $ d从django.db.models导入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

这是给我错误'模块'对象是不可调用的。有谁可以告诉我为什么? plz告诉我我失踪了什么

解决方案

我想你应该检查你的进口。 random 是模块名称和模块内的函数。如果你有

  import random 

然后你需要调用 random.random ,而不是只是 random


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

解决方案

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.

这篇关于'module'对象不可调用Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆