I have the following middleware:
class SimpleMiddleware:
def __init__(self, get_response):
self.get_response = get_response
self.login_path = '/login/'
self.home_path = '/'
def __call__(self, request):
if request.user.is_authenticated and request.path == self.login_path:
return redirect(self.home_path)
response = self.get_response(request)
return response
It is a good idea to redirect any already authed users to home page if they try to reach login page? Thanks in advance!
CodePudding user response:
There's a redirect_authenticated_user attribute in the LoginView.
from django.contrib.auth.views import LoginView
class CustomLoginView(LoginView):
redirect_authenticated_user = True
