title: csrfToken is only valid after page refresh - Django
body: <p>I am running into a weird issue with Django CSRF tokens in my SPA.</p>
  
  <p>When I render my application I ensure that the token is set using <code>ensure_csrf_cookie</code>. When I check my cookies I see that <code>csrftoken</code> is properly stored, and I'm also sending it as part of the request using:</p>
  
  <pre><code>     headers: {
         ‘X-CSRFToken’: getCsrfTokenFromCookie(),
       }
  </code></pre>
  
  <p>When I delete the <code>csrfToken</code> cookie and refresh the page, a new <code>csrfToken</code> is set but when I try to send my request, I get the error</p>
  
  <blockquote>
    <p>message: "CSRF Failed: CSRF Token missing or incorrect."</p>
  </blockquote>
  
  <p>But if I refresh the page again, the request sends successfully with the same csrfToken cookie!</p>
  
  <p>I am not sure what is causing this inconsistency. Any thoughts?</p>