Django next page not working in login page

Issue

I open my browser, and try to access my Django site. I’m logged out of my account, so I get redirected to my login page, with the page I’m going to as a GET parameter.

http://website.com/login/?next=/customer/7/54

However, when I enter my login information, I get redirected to:

http://website.com/

Even though, I’m trying to get to:

http://website.com/customer/7/54

/customer/7/54 points to a view that does have the @login_required decorator, but I was under the assumption, that it’d still point to that view after I logged in.What is going on?

EDIT: So I realized, I had a hidden input tag:

    <input type="hidden" name="next" value='/'>

However, how do I pass in the GET paramter ‘/customer/7/54/ into the login template?

Solution

According to your edited question, you can get next parameter at login page as follows:

<input type="hidden" name="next" value="{{ next }}">

The standart django’s django.contrib.auth.views.login passes next variable directly to the template context.
Also, read docs about user authentication:

You can also specify the name of the GET field which contains the URL
to redirect to after login by passing redirect_field_name to the view.
By default, the field is called next.

But you, probably, don’t need to change this.

Answered By – Serhii Holinei

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published