Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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 -> ', 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
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement