title: Python/Django: How to display error messages on invalid login?
body: <p>I'm trying to do the Login for my Django (2.0) website, so far I've got the login working for existing accounts. I'm using the built-in login function.</p>
  
  <p>Now I want to display an error message when you enter an invalid account, for example "Invalid username or password!". But I have no idea how to go about this.</p>
  
  <p>Right now it just refreshes the login page when your enter an invalid account. Any help is appreciated!</p>
  
  <p>Login.html</p>
  
  <pre><code>{% block title %}Login{% endblock %}
  
  {% block content %}
    &lt;h2&gt;Login&lt;/h2&gt;
    &lt;form method="post"&gt;
      {% csrf_token %}
      {{ form.as_p }}
      &lt;button type="submit"&gt;Login&lt;/button&gt;
    &lt;/form&gt;
  {% endblock %}
  </code></pre>
  
  <p>Login view</p>
  
  <pre><code>def login(request):
      if request.method == 'POST':
          form = AuthenticationForm(request.POST)
          username = request.POST['username']
          password = request.POST['password']
          user = authenticate(username=username, password=password)
  
          if user is not None:
              if user.is_active:
                  auth_login(request, user)
                  return redirect('index')
  
      else:
          form = AuthenticationForm()
      return render(request, 'todo/login.html', {'form': form})
  </code></pre>