title: Session is not storing variables - Django
body: <p>I've been having trouble storing my tokens on session.<br />
  I've found few solutions on stackoverflow but none of them worked.<br /></p>
  
  <p>currently, I store user's token when client send a POST request to <em>/api/login</em></p>
  
  <p>and here is my views logic</p>
  
  <pre><code>request.session['token'] = auth.token.key
  request.session.modified = True
  </code></pre>
  
  <ul>
  <li>I'm 100% sure <code>auth.token.key</code> is not <code>None</code> and the logic stores just fine.</li>
  </ul>
  
  <p>but when it comes to <em>/api/update</em> (some sample api),
  I always get <code>None</code></p>
  
  <p>here is how I get the Item from session:</p>
  
  <pre><code>print(request.session.get('token'))
  </code></pre>
  
  <p>** The Code above always returns None**</p>
  
  <p>I read the Django docs. I set both the session middleware and session app:</p>
  
  <pre><code>INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'rest_framework',
      'rest_framework.authtoken',
      'user'
  ]
  
  MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  ]
  
  AUTHENTICATION_BACKENDS = (
          'user.auth.AuthBackend',
          'django.contrib.auth.backends.RemoteUserBackend',
          'django.contrib.auth.backends.ModelBackend',
  )
  </code></pre>
  
  <p>I've done all the migrations.<code>django_session</code> table exists.</p>
  
  <p><strong>EDITED:</strong></p>
  
  <p>login view:</p>
  
  <ul>
  <li>I have custome authentication backend</li>
  </ul>
  
  <pre><code>@api_view(['POST'])
  def login(request):
  
      # convert json data into dictionary
      data = get_data(request)
  
      print(request.session.get('token'))
  
      auth = authenticate(
          email = data['email'],
          password = data['password']
      )
  
      if auth:
          # store user's token into sesion
          request.session['token'] = auth.token.key
          print(request.session['token'])
  
          user = UserModelSerializer(auth.user)
  
          return Response(
              user.data,
              status = status.HTTP_200_OK
          )
  
      else:
  
          return Response(
              message("user doestn't exist | incorrect password"),
              status = status.HTTP_403_FORBIDDEN
          )
  </code></pre>
  
  <p>Update View (where I can't get the session data):</p>
  
  <pre><code>@api_view(['POST'])
  def update(request):
      print(request.session.get('token'))
      return Response("its ok.")
  </code></pre>