Answer the question
In order to leave comments, you need to log in
How to check in Base Views that the user is already logged in and not show him the login page?
class LoginFormView(FormView):
form_class = AuthenticationForm
template_name = "login.html"
success_url = "/"
def form_valid(self, form):
self.user = form.get_user()
login(self.request, self.user)
return super(LoginFormView, self).form_valid(form)
Answer the question
In order to leave comments, you need to log in
from django.urls import reverse
from django.shortcuts import redirect
class AlreadyLoggedIn(object):
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated:
return redirect(reverse('your-url'))
else:
return super(AlreadyLoggedIn, self).dispatch(request, *args, **kwargs)
class LoginFormView(AlreadyLoggedIn, FormView):
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question