title: Django - Login - Forbidden (CSRF token missing or incorrect.):
body: <p>I am getting the <code>Forbidden (CSRF token missing or incorrect.)</code> error  when I try to use login page. </p>
  
  <p>The scenario is as follows:</p>
  
  <ol>
  <li>An user has two tabs open.</li>
  <li>Both tabs are login pages.</li>
  <li>In tab 1, user successfully logged in, and was redirected to a new page where login is required.</li>
  <li>In tab 2, user hasn't refreshed the page, and is still in the login page. In the Django backend, user is already authenticated, but the front-end template hasn't noticed it yet.</li>
  <li>In tab 2, when I click on login button, I get <code>Forbidden (CSRF token missing or incorrect.)</code> error.</li>
  <li>I made sure that <code>csrf_token</code> is in the form. </li>
  <li>This error occurs only when I'm using two tabs.</li>
  <li>I'm using AJAX</li>
  </ol>
  
  <p>Why is this happening? How can I fix it? </p>
  
  <p>I don't know this would help, but here is my <code>views.py</code> for login</p>
  
  <pre><code>class Login_View(LoginView):
  
      template_name = 'login.html'
  
      def post(self, request, *args, **kwargs):
          username = request.POST['username']
          password = request.POST['password']
          user = authenticate(username=username, password=password)
  
          response_data = {}
          if user is not None:
              if user.is_active:
                  login(request, user)
                  response_data['result'] = 'success'
              else:
                  return HttpResponse("Inactive user.")
          else:
              response_data['result'] = 'fail'
  
          return HttpResponse(json.dumps(response_data), content_type="application/json")
  </code></pre>