Reputation: 4870
In my urls.py, I map the url accounts/login/ to the login module, with a reference to the template i want to use:
url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'templates/login.html'})
This works fine, but I want to change the value of the next
property, which specified where the user ought to be redirected after a successful login. How can I access these variables and print their values, and more importantly, how can I modify them?
Thanks!
Upvotes: 1
Views: 1257
Reputation: 14080
Direct the url to a view:
(r'^accounts/login/', 'myproj.login.views.mylogin')
Then handle redirection in your view code:
def mylogin(request, **kwargs):
if request.user.is_authenticated():
if 'next_url' in request.session:
url = request.session['next_url']
del request.session['next_url'] # Cleaning next_url val
return HttpResponseRedirect('/%s' % url)
else:
return HttpResponseRedirect('/')
return login(request, **kwargs)
@csrf_protect
def login(request, template_name='registration/login.html'):
"""Displays the login form and handles the login action."""
retval = django.contrib.auth.views.login(request, template_name)
clear_session_data(request.session)
return retval
Upvotes: 1