Django App Engine: AttributeError: 'AnonymousUser' object has no attribute 'backend'

柔情痞子 提交于 2019-12-05 06:32:48

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().

Raz

Had the same problem. But the problem was that the username was to long and it was truncated to 30 characters. Found the answer here:

Django Register Form 'AnonymousUser' object has no attribute 'backend'

That happens when user was not authenticated. Be sure that you are using same field for loging Backend... for example I am loging with email (Backend that uses email and password) so

django.contrib.auth.authenticate(username=username, password=password)

if for me

django.contrib.auth.authenticate(username=email, password=password)

The backend is here: http://www.micahcarrick.com/django-email-authentication.html

If you are using replication in your database and happen to be reading from Read replica while writing to your master/default database, then if there is a replication lag that could also cause this. You will write to the master while authenticate will try to read from read replica resulting in not finding the User.

The solution is to set up your routers to use default db for User queries.

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