I faced a similar issue (request.user becoming anonymous after login) and found
the following solution. It had to do with the naming convention for the
auth backend under AUTHENTICATION_BACKENDS in settings.py. I had a custom
auth backend class called PamBackend which I had in a file called PamBackend.py.
I listed it under AUTHENTICATION_BACKENDS as 'auth_backends.PamBackend'. This
seemed to work ok--authentication was happening as expected, returning a valid
user--but the request.user would disappear after a page redirect.
The key is that the backend name is set in the session when authenticate() is
called (in django.contrib.auth). It sets the name like this:
user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__)
So in my case, the name was set to 'auth_backends.PamBackend.PamBackend'.
For a new http request, django checks the session and gets:
1) the name of the auth backend, and
2) the user id.
It then calls get_user (in django/contrib/auth/__init__.py) which does the following:
1) gets the backend name from the session,
2) checks for a match in settings, and
3) calls the appropriate get_user method from the appropriate backend.
So at this point, my backend name did not match what was in settings.py and
it returned an anonymous user.
-Scott