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)
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):
...