login_required redirects always to LOGIN_REDIRECT_URL?

425 views
Skip to first unread message

Jarek Zgoda

unread,
Dec 22, 2008, 8:47:32 AM12/22/08
to Django users
I'm seeing strange behaviour of login_required decorator: any view
decorated with it first sends to login page, then to url defined in
LOGIN_REDIRECT_URL. The url to decorated view is supplied in next
parameter (/login/?next=/path/to/view/) but is never executed.

Looking at login view code I see that the redirect is taken from
redirect_field_name field (which in my case is default "next") of
REQUEST. This works as I expect if I do GET, but this value is not set
if I issue POST request with credentials after displaying form.

Do I have to write my own login machinery to achieve such
functionality (redirect to decorated view after login)?

Cheers
J.

Matias

unread,
Dec 22, 2008, 2:40:56 PM12/22/08
to django...@googlegroups.com
Hello,

You can add a hidden input named "next" where you put the value of next in the GET variable.
Like this
<form method="post" action="{{ some_action }}" ... >
....
<input type="hidden" name="next" value="{{ request.GET.next }}" />
....
</form>

Or you can change the action variable of the form to include the current GET variables. like this

<form method="post" action="{{ request.get_full_path }}" ... >
....
</form>

If your view that handles GET and POST aren't the same you must add the "next" var in the action field on your own.


The latter is the best IMHO.

Hope that helps!

Regards,
Matias.
--
:wq

Jarek Zgoda

unread,
Dec 23, 2008, 4:40:57 AM12/23/08
to django...@googlegroups.com
Wiadomość napisana w dniu 2008-12-22, o godz. 20:40, przez Matias:

> You can add a hidden input named "next" where you put the value of
> next in the GET variable.
> Like this
> <form method="post" action="{{ some_action }}" ... >
> ....
> <input type="hidden" name="next" value="{{ request.GET.next }}" />
> ....
> </form>
>
> Or you can change the action variable of the form to include the
> current GET variables. like this
>
> <form method="post" action="{{ request.get_full_path }}" ... >
> ....
> </form>
>
> If your view that handles GET and POST aren't the same you must add
> the "next" var in the action field on your own.
>
>
> The latter is the best IMHO.


Thanks. I was hoping there's something that would save me from writing
actual code. Django makes me too lazy, I have to get my hands dirty
with Spring again. ;)

--
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R&D, Redefine
jarek...@redefine.pl

Reply all
Reply to author
Forward
0 new messages