title: Django React Axios
body: <p>I am trying to make a post request to a Django server using React with Axios. However, I am getting a redirect 302 on the server side.</p>
  
  <p>Just followed all suggestions in this post here <a href="https://stackoverflow.com/questions/39254562/csrf-with-django-reactredux-using-axios">CSRF with Django, React+Redux using Axios</a>
  unsuccessfully :(</p>
  
  <p>However, what I have done so far is the following:
  Sat the default axios CookieName and HeaderName (on the javascript side):</p>
  
  <pre><code>axios.defaults.xsrfHeaderName = "X-CSRFToken";
  axios.defaults.xsrfCookieName = "XCSRF-Token";
  </code></pre>
  
  <p>Got this in <code>settings.py</code> as well:</p>
  
  <pre><code>CSRF_COOKIE_NAME = "XCSRF-Token"
  </code></pre>
  
  <p>And here is how the post request looks like:</p>
  
  <pre><code>axios(
      {
          method: 'post',
          url: `/api/${selectedEntryType}_entry`,
          data: {
              "test": "test"
          },
          headers: {
              'X-CSRFToken': document.cookie.split('=')[1],
              'X-Requested-With': 'XMLHttpRequest',
              'Content-Type': 'application/json',
          }
      }
  )
  </code></pre>
  
  <p>Another thing that I have tried is to make the post request from the Django rest api UI:
  <a href="https://i.stack.imgur.com/WpEwn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WpEwn.png" alt="Django rest api UI"></a></p>
  
  <p>and it does work successfully. </p>
  
  <p>The only differences in the Request Headers when I make the request from the UI and from JS are:
  <code>Accept</code>, <code>Content-Length</code>, and <code>Referer</code>, which I don't see how could they be problematic. </p>
  
  <p>Please help.</p>