django auth:authenticate() 出现奇怪的错误
我正在使用authenticate() 手动验证用户身份。 没有“last_login”属性
使用管理界面,我可以看到用户调试回溯
Environment:
Request Method: GET
Request URL: https://localhost/login/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'mobius.polls']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/contrib/auth/__init__.py" in login
55. user.last_login = datetime.datetime.now()
Exception Type: AttributeError at /login/
Exception Value: 'unicode' object has no attribute 'last_login'
:我不明白,为什么会出现这种差异。
任何形式的帮助将不胜感激。提前致谢!
I am using authenticate() to authenticating users manually.
Using admin interface I can see that there is no 'last_login' attribute for Users
Debug traceback is :
Environment:
Request Method: GET
Request URL: https://localhost/login/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'mobius.polls']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/contrib/auth/__init__.py" in login
55. user.last_login = datetime.datetime.now()
Exception Type: AttributeError at /login/
Exception Value: 'unicode' object has no attribute 'last_login'
I cant figure out, why is there this discrepancy.
Any kind of help would be appreciated. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题不在于
authenticate()
,它似乎在于login()
,您似乎将unicode
传递给它,而不是比django.contrib.auth.models.User
对象。您可能应该从
authenticate()
验证并登录 文档
The problem isn't with
authenticate()
, it seems to be withlogin()
which you appear to be passing aunicode
into, rather than adjango.contrib.auth.models.User
object.You should probably be getting that User object from
authenticate()
authenticate and login docs
异常值告诉它:“user”是一个 unicode 对象,而不是 django.contrib.auth.models.User 对象。您确定数据库可以访问吗?尝试:
此代码必须正确工作。如果没有,那么您的数据库设置有问题。 (也许您没有执行
python manage.pysyncdb
?)请同时发布您的settings.py 的数据库相关部分。根据您当前的信息,很难找到问题的原因。
完整回溯也很有帮助。
The exception value tells it: "user" is a unicode object instead of a django.contrib.auth.models.User object. Are you sure that the database is accessible? try:
This code must work correctly. If not, then there's something wrong with your database setup. (maybe you did not do
python manage.py syncdb
?)Please post your database related parts of settings.py as well. From your current information it's not easy to find the cause of your problem.
The full traceback is helpful as well.