Django login redirect not working?

mpen picture mpen · Feb 14, 2010 · Viewed 10.4k times · Source

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?

Answer

mpen picture mpen · Feb 15, 2010

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.