How to redirect to the last visited page after login/registration completion

122 views
Skip to first unread message

olive

unread,
Dec 10, 2005, 5:02:00 AM12/10/05
to Django users
Hello,

login and registration may requires several steps/forms/pages to
complete.

How do I redirect, after login registration completion, to the last
page visited before the first login/registration page ?

Do I need to save each visited page (request.path) to the session ?

If this is the way to go, how do I save the path of a generic view ?

Cheers,

Olivier.

olive

unread,
Dec 10, 2005, 5:07:08 AM12/10/05
to Django users
I would like to add that a link to the login/registration form appears
on each page of my site (i.e defined in base.html)

hugo

unread,
Dec 10, 2005, 8:53:20 AM12/10/05
to Django users
>How do I redirect, after login registration completion, to the last
>page visited before the first login/registration page ?

You can pass a "next" parameter to the login view, so the form can put
that into a "next" hidden field to jump back from where you came. Or
another way would be for your login view to use the referer to jump
back from where you came (and hand that "next" information down to any
subsequent page, of course).

I don't think that storing the URL in the session would be a sensible
idea, because the user can easily "clone" pages pointing to the same
session data - just opening a link in a new tab/window won't create a
new session, so those windows could possibly stomp on each others
stored data.

The login form view already handles a "next" input field in that it
redirects to that URL on submit, so that's the way I would (and I did)
address this problem.

bye, Georg

olive

unread,
Dec 10, 2005, 10:55:05 AM12/10/05
to Django users
Thanks Georg,

The referer method did the trick.

Olivier.

Reply all
Reply to author
Forward
0 new messages