title: Django Set Session Variable
body: <p>Hello awesome developers! </p>
  
  <p>I got stack with session variables.
  At the moment I have two functions. In the first one I am trying to set session var, it looks like that everything works fine, but in the second I am trying to access this var and I am getting None. Does any one have an idea why is it so?..</p>
  
  <p>Views.py</p>
  
  <pre><code>@api_view(['POST']) 
  def login(request):
      if request.method == 'POST':
          response = requests.post(CORE_ADDRESS + 'login/', json=request.data)
  
      if response.status_code == 200:
          response = response.json()
          request.session["authentication_token"] = response.get('authentication_token')
          request.session["session_user_id"] = response.get('id')
  
          print('token -&gt; ', request.session["authentication_token"])
          #token prints fine here
  
      return Response(response)
  
  
  
  @api_view(['GET'])
  def session_user(request):
      if request.method == 'GET':
          print(request.session.get('authentication_token'))
          #and here it prints None
  </code></pre>
  
  <p>Settings.py</p>
  
  <pre><code>INSTALLED_APPS = [
  'backend',
  'django.contrib.admin',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles',
  'corsheaders',
  'rest_framework',
  ]
  
  MIDDLEWARE_CLASSES = [
      #'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      #'django.middleware.common.CommonMiddleware',
      #'django.middleware.csrf.CsrfViewMiddleware',
      #'django.contrib.auth.middleware.AuthenticationMiddleware',
      #'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      #'django.middleware.clickjacking.XFrameOptionsMiddleware',
      'corsheaders.middleware.CorsMiddleware',
      'django.middleware.common.CommonMiddleware',
  ]
  
  ROOT_URLCONF = 'myapp.urls'
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  
  WSGI_APPLICATION = 'myapp.wsgi.application'
  
  
  # Database
  # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      }
  }
  
  
  # Password validation
  # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
  
  AUTH_PASSWORD_VALIDATORS = [
      {
          'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
      },
  ]
  
  REST_FRAMEWORK = {
      'DEFAULT_AUTHENTICATION_CLASSES': [],
      'DEFAULT_PERMISSION_CLASSES': [],
      'PAGE_SIZE': 10
  }
  
  
  # Internationalization
  # https://docs.djangoproject.com/en/1.9/topics/i18n/
  
  LANGUAGE_CODE = 'en-us'
  
  TIME_ZONE = 'UTC'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  CORS_ORIGIN_ALLOW_ALL = True
  </code></pre>
  
  <p>By the way, these functions are called from Angular frontend.</p>
  
  <p>Thanks in advance!</p>