1

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!

2
  • 1
    What part of the Django documentation have you actually read? Try reading about docs.djangoproject.com/en/1.2/ref/templates/api/… and then updating your question to be more specific. Commented Mar 8, 2011 at 1:54
  • culov, you are trying to do too much in your urls.py. There's no way you should specify the template there. Commented Mar 8, 2011 at 5:24

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.