views:

267

answers:

2

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?

+1  A: 

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.

stefanw
Uh....no. As I said, I get sent to `http://localhost:8000/login/?next=/listings/post/`. `next` contains the proper value.
Mark
+1  A: 

Needed to add

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

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

Mark
So I was right in the end, your next value was not set, that's why it redirected you to LOGIN_REDIRECT_URL.
stefanw
Well...okay, fine. You can have the check then. I thought it was set because it was appearing in the URL. But you still didn't really solve the problem ;)
Mark