title: Django Request Session on anonymous users
body: <p>I have the following problem:</p>
  
  <p>I'm using the Django Rest framework with anonymous users (i don't have users in my application) and in my views file when i try to modify the <code>request.session</code> variable, the value is not persistent in all views. I have two different class based views:</p>
  
  <pre><code>def post(self, request):
    ...
    request.session["instances"] = serializer.data 
    request.session.modified = True
    ...
    return Response(data, status=status.HTTP_200_OK)
  
  def get(self, request, page):
    ...
    print request.session["instances"]
    ...
    return Response(data, status=status.HTTP_200_OK)
  </code></pre>
  
  <p>On the second view i get a key error, basically the key "instances" doesn't exist. This is my settings file:</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',
      'corsheaders',
  ]
  
  MIDDLEWARE = [
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.security.SecurityMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
      'corsheaders.middleware.CorsMiddleware',
  ]
  
  SESSION_SAVE_EVERY_REQUEST = True
  
  ############
  # SESSIONS #
  ############
  
  # Cache to store session data if using the cache session backend.
  SESSION_CACHE_ALIAS = 'default'
  # Cookie name. This can be whatever you want.
  SESSION_COOKIE_NAME = 'sessionid'
  # Age of cookie, in seconds (default: 2 weeks).
  SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2
  # A string like ".example.com", or None for standard domain cookie.
  SESSION_COOKIE_DOMAIN = None
  # Whether the session cookie should be secure (https:// only).
  SESSION_COOKIE_SECURE = False
  # The path of the session cookie.
  SESSION_COOKIE_PATH = '/'
  # Whether to use the non-RFC standard httpOnly flag (IE, FF3+, others)
  SESSION_COOKIE_HTTPONLY = True
  # Whether a user's session cookie expires when the Web browser is closed.
  SESSION_EXPIRE_AT_BROWSER_CLOSE = False
  # The module to store session data
  SESSION_ENGINE = 'django.contrib.sessions.backends.db'
  # Directory to store session files if using the file session module. If None,
  # the backend will use a sensible default.
  SESSION_FILE_PATH = None
  # class to serialize session data
  SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
  
  #########
  # CACHE #
  #########
  
  # The cache backends to use.
  CACHES = {
      'default': {
          'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
      }
  }
  CACHE_MIDDLEWARE_KEY_PREFIX = ''
  CACHE_MIDDLEWARE_SECONDS = 600
  CACHE_MIDDLEWARE_ALIAS = 'default'
  </code></pre>
  
  <p>I haven't been able to store data on <code>request.session</code> successfully, i tried checking if the session has a <code>session_key</code> but it prints <code>None</code>, so i created a session on the first view with <code>session_id = request.session._get_or_create_session_key()</code> but still on the second view it doesn't exist anymore (<code>session_key</code> is <code>None</code>). Anybody here had this problem before?</p>