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 = user
and saving the user id in session.
However, on subsequent requests, I am not able to retrieve the request.user. It is always an AnonymousUser. I can, however, retrieve the user id from the session and can confirm that the session cookie is being set correctly.
What am I missing?
I do not want to use a relational db as I want to maintain all my user data in couchdb.
Edit: I have written a class which does not inherit from Django's auth User. It, however, has the username and email attributes. For this reason, my backend does not return a class which derives from auth User.
Best Answer
The
request.user
is set by thedjango.contrib.auth.middleware.AuthenticationMiddleware
.Check
django/contrib/auth/middleware.py
:Then look at the
get_user
function indjango/contrib/auth/__init__.py
:Your backend will need to implement the
get_user
function.