Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django login redirect not working?

I go to my webpage http://localhost:8000/listings/post/, it fails the test

@user_passes_test(lambda u: u.is_authenticated() and u.get_profile().shipper)

as expected, and redirects me to http://localhost:8000/login/?next=/listings/post/ like it's supposed to, but when I log in again, it doesn't redirect me back to that page like it's supposed to. It takes me to /accounts/profile/. I haven't defined redirect_field_name anywhere, so it should be looking for the default next variable. The relevant urls.py bit looks like this

url(r'^login/$', 'django.contrib.auth.views.login', name='login'),

So what are the possible causes for this?

like image 667
mpen Avatar asked Feb 14 '10 21:02

mpen


2 Answers

Needed to add

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

To my login form. It was posting back to the login URL without the next token, and then trying to redirect.

like image 89
mpen Avatar answered Oct 04 '22 06:10

mpen


It redirects you to the settings variable LOGIN_REDIRECT_URL.

This happens when the following is true:

if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL

Most probably your 'next' variable is empty or contains garbage.

like image 45
stefanw Avatar answered Oct 04 '22 06:10

stefanw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!