Custom LoginView in Django 2
问题 I am trying to customise the authentication and view in Django 2 but the problem is that if the user is already authenticated the login form is still shown and it is not redirected to the appropriate URL. To get over this I have done the following: class CustomLoginView(LoginView): form_class = LoginForm template_name = 'login.html' def get_initial(self): if self.request.user.is_authenticated and self.request.user.is_staff and has_2fa(self.request.user): return HttpResponseRedirect(reverse('{