Django, request.user is always Anonymous User

后端 未结 9 2087
无人共我
无人共我 2020-12-01 14:57

I am using a custom authentication backend for Django (which runs off couchdb). I have a custom user model.

As part of the login, I am doing a request.user = u

9条回答
  •  不思量自难忘°
    2020-12-01 15:13

    I had similar problem when I used custom authentication backend. I used field different than the primary key in the method get_user. It directly solved after using primary key which must be number (not str)

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id) # <-- must be primary key and number
        except User.DoesNotExist:
            return None
    

提交回复
热议问题