Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. @api_view(['POST'])
  2. def login(request):
  3. if request.method == 'POST':
  4. response = requests.post(CORE_ADDRESS + 'login/', json=request.data)
  5.  
  6. if response.status_code == 200:
  7. response = response.json()
  8. request.session["authentication_token"] = response.get('authentication_token')
  9. request.session["session_user_id"] = response.get('id')
  10.  
  11. print('token -> ', request.session["authentication_token"])
  12. #token prints fine here
  13.  
  14. return Response(response)
  15.  
  16.  
  17.  
  18. @api_view(['GET'])
  19. def session_user(request):
  20. if request.method == 'GET':
  21. print(request.session.get('authentication_token'))
  22. #and here it prints None
  23.  
  24. INSTALLED_APPS = [
  25. 'backend',
  26. 'django.contrib.admin',
  27. 'django.contrib.auth',
  28. 'django.contrib.contenttypes',
  29. 'django.contrib.sessions',
  30. 'django.contrib.messages',
  31. 'django.contrib.staticfiles',
  32. 'corsheaders',
  33. 'rest_framework',
  34. ]
  35.  
  36. MIDDLEWARE_CLASSES = [
  37. #'django.middleware.security.SecurityMiddleware',
  38. 'django.contrib.sessions.middleware.SessionMiddleware',
  39. #'django.middleware.common.CommonMiddleware',
  40. #'django.middleware.csrf.CsrfViewMiddleware',
  41. #'django.contrib.auth.middleware.AuthenticationMiddleware',
  42. #'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
  43. 'django.contrib.messages.middleware.MessageMiddleware',
  44. #'django.middleware.clickjacking.XFrameOptionsMiddleware',
  45. 'corsheaders.middleware.CorsMiddleware',
  46. 'django.middleware.common.CommonMiddleware',
  47. ]
  48.  
  49. ROOT_URLCONF = 'myapp.urls'
  50.  
  51. TEMPLATES = [
  52. {
  53. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  54. 'DIRS': [],
  55. 'APP_DIRS': True,
  56. 'OPTIONS': {
  57. 'context_processors': [
  58. 'django.template.context_processors.debug',
  59. 'django.template.context_processors.request',
  60. 'django.contrib.auth.context_processors.auth',
  61. 'django.contrib.messages.context_processors.messages',
  62. ],
  63. },
  64. },
  65. ]
  66.  
  67. WSGI_APPLICATION = 'myapp.wsgi.application'
  68.  
  69.  
  70. # Database
  71. # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
  72.  
  73. DATABASES = {
  74. 'default': {
  75. 'ENGINE': 'django.db.backends.sqlite3',
  76. 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  77. }
  78. }
  79.  
  80.  
  81. # Password validation
  82. # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
  83.  
  84. AUTH_PASSWORD_VALIDATORS = [
  85. {
  86. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  87. },
  88. {
  89. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  90. },
  91. {
  92. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  93. },
  94. {
  95. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  96. },
  97. ]
  98.  
  99. REST_FRAMEWORK = {
  100. 'DEFAULT_AUTHENTICATION_CLASSES': [],
  101. 'DEFAULT_PERMISSION_CLASSES': [],
  102. 'PAGE_SIZE': 10
  103. }
  104.  
  105.  
  106. # Internationalization
  107. # https://docs.djangoproject.com/en/1.9/topics/i18n/
  108.  
  109. LANGUAGE_CODE = 'en-us'
  110.  
  111. TIME_ZONE = 'UTC'
  112.  
  113. USE_I18N = True
  114.  
  115. USE_L10N = True
  116.  
  117. USE_TZ = True
  118.  
  119. CORS_ORIGIN_ALLOW_ALL = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement