How to raise condition based error messages in django login?

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.”

Can you verify that the username and password you’re supplying for the inactive user are correct?

Looking at the source for AuthenticationForm shows that it validates the password before checking whether or not the user is active. (See clean method) So the user needs to be able to authenticate before they’re checked to see if they’re active.

Ken

thanks for your reply and for your valuable time