Issue
How can I get the user object that login() has save in the session?
user= request.session.get('user')
returns nothingIn this example:
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
Solution
AuthenticationMiddleware adds the user attribute, representing the currently-logged-in user, to every incoming HttpRequest object. Authentication middleware requires session middleware to be installed. So, you should add this middlewares in settings.py to MIDDLEWARE_CLASSES tuple:
MIDDLEWARE_CLASSES = (
#...
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
#...
)
Answered By - ndpu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.