我的代码很简单,看起来像:
user = User.objects .create_user(username,username,password) user.set_password(password) user.save() user = django.contrib.auth.authenticate(username = username,密码=密码) django.contrib.auth.login(请求,用户)我只有在生产时才会产生以下错误:
web req_create:'AnonymousUser'对象没有属性'后端'追溯(最近的最后一次呼叫):文件/base/data/home/apps/s~XXXXX/1.356802202883392818/XXXX/XXX.py,第332行,req_create login(请求,用户)文件/base/data/home/apps/s~XXXXX/1.356802202883392818/django/contrib/auth/__init__.py,第82行,登录 request.session [BACKEND_SESSION_KEY] = user.backend AttributeError:'AnonymousUser'对象没有属性'后端'我不确定,但我有一个不好的感觉,这个异常是由于高复制数据存储及其最终的一致性。我认为 authenticate()保存用户值,而 login()执行查询,但用户值没有而是传播到HRDS。任何人都可以确认这是真的吗?如果是这样,它将如何修复?
解决方案当您保存用户时,将不会自动激活。请查看 AnonymousUser 的链接这说明您的用户如何成为 AnonymousUser 。
所以你必须设置所有可能使你的用户的项目 AnonymousUser 。在验证之前,请检查 user.is_anonymous()。
I am using djangoappengine. When I try create a new user, authenticate that user, and log them in, I get the following error AttributeError: 'AnonymousUser' object has no attribute 'backend'.
My code is simple and looks like:
user = User.objects.create_user(username, username, password) user.set_password(password) user.save() user = django.contrib.auth.authenticate(username=username, password=password) django.contrib.auth.login(request, user)I only get the following error on production and only occasionally:
web req_create: 'AnonymousUser' object has no attribute 'backend' Traceback (most recent call last): File "/base/data/home/apps/s~XXXXX/1.356802202883392818/XXXX/XXX.py", line 332, in req_create login(request, user) File "/base/data/home/apps/s~XXXXX/1.356802202883392818/django/contrib/auth/__init__.py", line 82, in login request.session[BACKEND_SESSION_KEY] = user.backend AttributeError: 'AnonymousUser' object has no attribute 'backend'I am not sure, but I have a bad feeling that this exception is due to the high replication data store and its eventual consistency. I think that authenticate() saves the user value and that login() does a query but the user value has not yet propagated into the HRDS. Can anyone confirm this to be true? If so, how would it be fixed?
解决方案When you save the user it will be not activate automatically. Please check the link for AnonymousUser which says how your user become AnonymousUser.
So you have to set all items which may be make your user as AnonymousUser. Before authenticate please check user.is_anonymous().
更多推荐
Django App Engine:AttributeError:'AnonymousUser'对象没有属性'后端'
发布评论