title: Override Django LoginView Error Message With Custom AuthenticationForm
body: <p>I have a class-based view that subclasses <code>LoginView</code>.</p>
  
  <pre><code>from django.contrib.auth.views import LoginView
  
  class CustomLoginView(LoginView):
  
  def get_success_url(self):
      url = self.get_redirect_url()
      return url or reverse_lazy('knowledgebase:user_home', kwargs={
          'username':self.request.user.username,
      })
  </code></pre>
  
  <p>I want to override the error message if a user's email is not yet active because they have to click a link sent to their email address. The current default message looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/sS6Sp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sS6Sp.png" alt="override LoginView error message"></a></p>
  
  <p>Instead of saying:</p>
  
  <blockquote>
    <p>Please enter a correct email address and password. Note that both
    fields may be case-sensitive.</p>
  </blockquote>
  
  <p>I want to say something to the effect of:</p>
  
  <blockquote>
    <p>Please confirm your email so you can log in.</p>
  </blockquote>
  
  <p>I tried:</p>
  
  <h3>accounts/forms.py</h3>
  
  <pre><code>from django.contrib.auth.forms import AuthenticationForm
  from django.utils.translation import gettext as _
  
  class PickyAuthenticationForm(AuthenticationForm):
      def confirm_login_allowed(self, user):
          if not user.is_active:
              raise forms.ValidationError(
                  _("Please confirm your email so you can log in."),
                  code='inactive',
              )
  </code></pre>
  
  <h3>accounts/views.py</h3>
  
  <pre><code>class CustomLoginView(LoginView): # 1. &lt;--- note: this is a class-based view
  
      form_class = PickyAuthenticationForm # 2. &lt;--- note: define form here?
  
      def get_success_url(self):
          url = self.get_redirect_url()
          return url or reverse_lazy('knowledgebase:user_home', kwargs={
              'username':self.request.user.username,
          })
  </code></pre>
  
  <p>The result is absolutely no effect when I try to log in with a user that <strong>does</strong> exist, but hasn't verified their email address yet.</p>
  
  <p><a href="https://docs.djangoproject.com/en/3.0/topics/auth/default/#django.contrib.auth.forms.AuthenticationForm" rel="nofollow noreferrer">AuthenticationForm docs</a>.</p>