Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why second user login redirects me to /accounts/profile/ url?

I am using Django built in view for user login:

url(r'^user/login/$', 'django.contrib.auth.views.login', {'template_name': 'users/templates/login.html'}, name='user-login'), 

After login when I goto user/login again I can login second time. I submit the form and getting:

The current URL, accounts/profile/, didn't match any of these.

I haven't declare this url in urls.py.

What I am doing wrong? Why framework want to redirect to this url?

like image 966
Codium Avatar asked Nov 01 '12 22:11

Codium


2 Answers

django.contrib.auth.views.login redirects you to accounts/profile/ right after you log in.
You may want to set LOGIN_REDIRECT_URL inside your settings.py file to anything you like..

like image 121
Traian Avatar answered Oct 24 '22 18:10

Traian


Explained in doc:

(accounts/profile/ is ...) The URL where requests are redirected after login when the contrib.auth.login view gets no next parameter.

Because you are yet authenticated your request is redirected to this url. To avoid redirect you should logout user before send it to user/login, create your custom login view or append Next parameter.

like image 21
dani herrera Avatar answered Oct 24 '22 17:10

dani herrera