Wednesday, 15 February 2012

authentication - How do I add something to Django's response context after a successful login? -



authentication - How do I add something to Django's response context after a successful login? -

i have django project in have wrapper around standard login view:

from django.contrib.auth import views auth_views myapp.forms import loginform def login(request, *args, **kwargs): """wrapper auth.login.""" kwargs['template_name'] = 'login.html' kwargs['authentication_form'] = loginform auth_view_response = auth_views.login(request, *args, **kwargs) homecoming auth_view_response

this works fine, want add together response context on next page, if login has been successful. i'm not sure how to:

check user has logged in after auth_views.login() called, or add variable show in context of next page.

speaking first question:

check user has logged in after auth_views.login() called, or

inside view function check request.user.is_authenticated()

speaking of sec question, can add together variable in user session , check on next page:

#in view mentioned above if request.user.is_authenticated(): request.session['some_key'] = "some_var" #in view, represents next page foo = request.session.get('some_key',none) #now can add together foo template context

django authentication

No comments:

Post a Comment