Search code examples
djangopinax

In Pinax/Django, how do I redirect to a link after logging in?


in Pinax, if I have a link that required login (i.e., I use the @login_required decorator), how do I redirect to that link after logging in, instead of being redirected to "what's next"???

Thanks


Solution

  • Simply set the LOGIN_REDIRECT_URL setting.

    EDIT It seems Pinax also supports another setting, LOGIN_REDIRECT_URLNAME, which seems to do the same thing as LOGIN_REDIRECT_URL, but is set to the url name, presumably so you don't have to make a call to reverse in your settings.py file.

    For more 'dynamic' redirects, the pinax.apps.account.views.login view uses pinax.apps.account.utils.get_default_redirect to look for a redirect URL from the following:

    1. A GET or POST parameter named 'next' (by default, though it is possible to customize).
    2. The LOGIN_REDIRECT_URL setting
    3. The LOGIN_REDIRECT_URLNAME setting

    The code in get_default_redirect actually is checking in the session for a 'redirect_to' key, which presumably holds one of the values defined in the settings, as the method makes no attempt to look at django.conf.session on it's own. The docstring claims that it checks for those settings, however, and that seems to be what you are experiencing in your project.