My custom login form:-
class MyAuthForm(AuthenticationForm):
error_messages = {
'invalid_login': _(
"Please enter a correct %(username)s and password."
),
'inactive': _("This account is inactive."),
}
def confirm_login_allowed(self, user):
if not user.is_active:
raise forms.ValidationError(
self.error_messages['inactive'],
code='inactive',
)
def get_user(self):
return self.user_cache
def get_invalid_login_error(self):
return forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={'username': self.username_field.verbose_name},
)
my Views.py:
from django.contrib.auth.views import LoginView
class MyLoginView(LoginView):
authentication_form = MyAuthForm
I am trying to add error message for inactive user but it is always showing------>
“Please enter a correct %(username)s and password.”
I want to show for inactive users-----> “This account is inactive.”