title: Show error message if password and username incorrect in Django form_template
body: <p>I am trying to show an error when the user enters wrong login credentials using <code>form_template</code>. So far I tried the below approach but it is not working.</p>
  
  <p>Forms.py:</p>
  
  <pre><code>class UserForm(forms.Form):
      username=forms.CharField(max_length=50)
      password=forms.CharField(widget=forms.PasswordInput)
  
      model=User
      fields=['username', 'password']
  </code></pre>
  
  <p>Views.py:</p>
  
  <pre><code>class loginform(View):
  
      template_name='essay/Login.html'
      form_class=UserForm
  
      def get(self,request):     # if the request is get then only view the function
          form=self.form_class(None)
          return render(request, self.template_name, {'form': form})
  
      def post(self,request):
          form=self.form_class(request.POST)
          if form.is_valid():
              #user = form.save(commit=False)  # it doesnot save in database, it is used to et clean the values
              # clean data
              username = form.cleaned_data['username']
              password = form.cleaned_data['password']
  
              # authenticate user:
              user = authenticate(username=username, password=password)
  
              if user is not None:
                  login(request, user)
                  if(request.user.is_prof==True):
                      return redirect('essay:file', )
                  else:
                      return redirect('essay:stdprofile')
              else:
                  return render(request,self.template_name, {
                      'error_message': ' Login Failed! Enter the username and password correctly', })
          else:
              msg = 'Errors: %s' % form.errors.as_text()
              return HttpResponse(msg, status=400)
  
          return render(request, self.template_name, {'form': form})
  </code></pre>
  
  <p>Form_template:</p>
  
  <pre><code>{% for field in form %}
   &lt;div class="form-group"&gt;
    &lt;label class="control-label col-sm-2"&gt;{{ field.label_tag }}&lt;/label&gt; 
    &lt;div class="col-sm-10"&gt;{{ field }}&lt;/div&gt;   &lt;!-- inputs on the rigth --&gt;
   &lt;/div&gt;
  {% endfor %}  
  </code></pre>
  
  <p>Login.html:</p>
  
  <pre><code>&lt;body&gt;
      &lt;div class="login-card"&gt;
        &lt;h1&gt;Log-in&lt;/h1&gt;&lt;br&gt;
        &lt;form class="form-horizontal" action="" method="POST" enctype="multiport/form-data"&gt;
            {% csrf_token %}
            {% include 'essay/form_template.html' %}
            &lt;input type="submit" name="login" class="login login-submit" value="login"&gt;
        &lt;/form&gt;
        {% error_message %}
      &lt;/div&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>The problem I got when I enter invalid credentials, username and password fields vanish and it also does not display the error message.  </p>