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\'},
@CpS provided very good solution, I just want to enhance it a little bit:
For example, you have following urls:
urlpatterns = [
# django's login/logout
url(r'login/$', 'django.contrib.auth.views.login', name='login'),
url(r'logout/$', 'django.contrib.auth.views.logout', name='logout'),
url(r'logout-then-login/$', 'django.contrib.auth.views.logout_then_login', name='logout_then_login'),
url(r'^$', views.dashboard, name='dashboard')
]
and dashboard.html is where you want to redirect after successful login, then you can modify your settings.py file accordingly:
from django.core.urlresolvers import reverse_lazy
LOGIN_REDIRECT_URL=reverse_lazy('dashboard')
LOGIN_URL=reverse_lazy('login')
LOGOUT_URL=reverse_lazy('logout')
We are using reverse_lazy() to build the URLs dynamically. The reverse_lazy() function reverses URLs just like reverse() does, but you can use it when you need to reverse URLs before your project's URL configuration is loaded.