Django - Read The Current's User Authentication Backend Class
Solution 1:
The backend
attribute is added to the user
object when the user authenticates using the django.contrib.auth.authenticate(username='foo',password='bar')
function.
This function in turn calls all of the AUTHENTICATION_BACKENDS
you have specified in your settings.py
file, until it is able to authenticate successfully using one of them.
If your users are "logged in" but don't have a backend
attribute that probably means you're not properly authenticating them. Maybe you're calling your SFIUserBackend.authenticate
function directly, when you should be calling the django.contrib.auth.authenticate
function?
Check out these custom authentication docs.
Solution 2:
You should read it in the the view and send an appropriate human form of that class name as the message.
Solution 3:
While authenticate()
adds the user.backend
attribute and login()
saves it in the session, for some reason get_user()
does not add it back to the user. I have submitted a patch.
Therefore, in order to access it in another request, you need request.session[django.contrib.auth.BACKEND_SESSION_KEY]
.
You can also write a custom tag or add it to your context (under whatever name you want) for ease of use.
Post a Comment for "Django - Read The Current's User Authentication Backend Class"