title: If the username or password is invalid when logging in, how can appear an error on page without refreshing itself, Django
body: <p>I have a login pop-up and I want after typing wrong username or password to appear a error message, like usual 'Username or password is incorrect', but after pressing button on the site, it is refreshing and I need to open my pop-up again in order to see the error, how can I do the error msg to appear without refreshing the page.</p>
  <p><strong>Views.py</strong></p>
  <pre><code>def main(request):
      form = CreateUserForm()
  
      if &quot;register-btn&quot; in request.POST:
          ....
  
      elif &quot;login-btn&quot; in request.POST:
          username = request.POST.get('username-log')
          password = request.POST.get('password-log')
          user = authenticate(request, username=username, password=password)
          if user is not None:
              login(request, user)
              return redirect('/account')
          else:
              messages.info(request, 'Username or password is incorrect')
              #here I don't know what to write for the purpose of appearing the 
              #error messages on the page without refreshing it
  
      return render(request, 'accounts/main.html', context)
  </code></pre>
  <p><strong>Main.html</strong> ( briefly )</p>
  <pre><code>&lt;label&gt;Your login&lt;/label&gt;
  &lt;input name=&quot;username-log&quot; class=&quot;form-control&quot; type=&quot;text&quot; placeholder=&quot;Enter your login&quot;&gt;
  
  &lt;label&gt;Password&lt;/label&gt;
  &lt;input name=&quot;password-log&quot; class=&quot;form-control&quot; type=&quot;password&quot; placeholder=&quot;Enter your password&quot;&gt;
  
     {% for message in messages %}
        &lt;p id=&quot;messages&quot; class=&quot;xerr&quot;&gt; {{message}} &lt;/p&gt;
     {% endfor %}
  
  &lt;button name=&quot;login-btn&quot; class=&quot;btn btn_100&quot; type=&quot;submit&quot;&gt;LOG IN&lt;/button&gt;
  </code></pre>