Hi there,
I’m using the LoginView from the package django.contrib.auth views to render my login page.
That gives me the ability to directly create the url, and the template associated, without creating a custom view.
from django.contrib.auth import views as auth_views
path('connexion/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
The thing is, I built a decorator that make the unauthenticated pages for unauthenticated users only (ex: logged in users shall not access the login page) :
def unauthenticated_user(view_func):
def wrapper_func(request, *args, **kwargs):
if request.user.is_authenticated:
return redirect('home')
else:
return view_func(request, *args, **kwargs)
return wrapper_func
So I placed this decorator on top of each view that is concerned by this behavior, but I’m unable to do it for the login view (because I don’t have it anywhere in my views.py files).
How can I apply this decorator to the login view?