In my template, login.html
, I have:
{% if form.errors %}
{% if user.is_authenticated %}
<div class="alert alert-warning"><center>Your account doesn't have access to this utility.</center></div>
{% else %}
<div class="alert alert-warning"><center>Incorrect username or password!</center></div>
{% endif %}
{% endif %}
What I am trying to do is, if after form submission, user is inactive then display a different error message and if user is simply not authenticated then display Incorrect username password error message. This doesn't work. It always displays "Incorrect username or password!" in both the cases. However inside a view, user.is_authenticated returns True
even for inactive users.
I there any other wway to get this done? I also tried
{% if 'inactive' in form.errors %}
But this doesnt work too, even though when I try to print form.errors
, it shows text "This account is inactive" for inactive users.
EDIT: For view, I am simply using django's login view inside a custom login view
views.py:
from django.contrib.auth.views import login, logout
from django.shortcuts import render, redirect
def custom_login(request, **kwargs):
if request.user.is_authenticated():
return redirect('/homepage/')
else:
return login(request, **kwargs)