By default after login django redirects the user to an accounts/profile page or if you edit the LOGIN_REDIRECT_URL you can send the user to another page you specify in the settings.py. I want my users to, after logged in, not be able to go to the login page but instead be redirected to the LOGIN_REDIRECT_URL automatically. Is there a way of doing it using the default login view? Any input is appreciated.
0
votes
1 Answers
3
votes
You can use redirect_authenticated_user
in LoginView
to achieve that, reference here.
You can use it by customize your own LoginView or simply just override the property on the fly in the urlpatterns
like so:
urlpatterns = [
path('accounts/login/', auth_views.LoginView.as_view(template_name='myapp/login.html', redirect_authenticated_user=True)),
]
Hope that helps!
if request.user.is_authenticated
in your login view and redirect – Goran