Sometimes, we want to redirect logged in users from login page with Python Django.
In this article, we’ll look at how to redirect logged in users from login page with Python Django.
How to redirect logged in users from login page with Python Django?
To redirect logged in users from login page with Python Django, we can set the redirect_authenticated_user
argument when we call as_view
.
For instance, we write
from django.contrib.auth import views as auth_views
from django.urls import path
urlpatterns = [
path('login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
]
to call auth_views.LoginView.as_view
with the redirect_authenticated_user
to True
to redirect users from the login page to the destination once the user is logged in.
Conclusion
To redirect logged in users from login page with Python Django, we can set the redirect_authenticated_user
argument when we call as_view
.