title: Django rest framework Reactjs sessions not working
body: <p>So I have set up Django rest framework as a backend API for an e-commerce website. The website is displayed through a React frontend, which is not served by the django backend.</p>
  
  <p>I am currently running both the Django backend and the React frontend from their local development servers (<a href="http://127.0.0.1:8000" rel="nofollow noreferrer">http://127.0.0.1:8000</a> and <a href="http://127.0.0.1:3000" rel="nofollow noreferrer">http://127.0.0.1:3000</a> respectively). In the future they will be on separate domains, probably.</p>
  
  <p>When I set a session in a view, and read the content in another, this works if I just type in the urls for creating and reading directly into my browser (just for testing purposes). But when I access the backend through my frontend, sessions can not be accessed anymore, or don't seem stored. What will happen is that I get a KeyError when trying to access the data that I set in a previous view.</p>
  
  <p>I guess this has to do with something I have read about some time ago, but I find it hard to find the correct information on how to work with this. Does this have to do with the cookie with the session id not being available to the frontend, but only to the backend itself?</p>
  
  <p><strong>Main question:</strong>
  I would like to know how I can work with sessions, using the above settup, for keeping a shopping cart.</p>
  
  <p><strong>My backend code, just in case someone wonders:</strong></p>
  
  <pre><code>from django.http import HttpResponse
  
  
  def cart_add(request, product_id, update, quantity):
      request.session['one'] = 'created through "cart_add" view'
      return HttpResponse("Created a session - cart_add")
  
  
  def create(request):
      request.session['one'] = 'created through "read" view'
      return HttpResponse("Created a session - create")
  
  
  def read(request):
      print(request.session['one'])
  </code></pre>
  
  <p>I have removed some unnecessary code. </p>
  
  <ul>
  <li>The cart_add view is called from the React frontend, using an ajax call (axios).</li>
  <li>The create and the read view I called by typing their urls directly into the browser.
  (This is all done for testing purposes, just making sure sessions are working before I start to write the real code.)</li>
  </ul>