Django App Engine:AttributeError:'AnonymousUser'对象没有属性'后端'

编程入门 行业动态 更新时间:2024-10-26 09:22:39
本文介绍了Django App Engine:AttributeError:'AnonymousUser'对象没有属性'后端'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用djangoappengine。当我尝试创建一个新用户,验证该用户并登录时,我收到以下错误 AttributeError:'AnonymousUser'对象没有属性'后端'。 p>

我的代码很简单,看起来像:

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'对象没有属性'后端'

本文发布于:2023-10-22 08:15:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1516959.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后端   属性   对象   Engine   App

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!