· 5 years ago · Dec 02, 2019, 05:14 PM
1import os
2from corsheaders.defaults import default_headers
3
4# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
5BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
6
7
8# Quick-start development settings - unsuitable for production
9# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
10
11# SECURITY WARNING: keep the secret key used in production secret!
12# **Dont forget to add your secret key below
13SECRET_KEY = 'yoursecretkeyhere'
14
15# SECURITY WARNING: don't run with debug turned on in production!
16DEBUG = True
17
18ALLOWED_HOSTS = []
19
20# Application definition
21# added corsheaders app and simplejwt token blacklist feature
22INSTALLED_APPS = [
23 'django.contrib.admin',
24 'django.contrib.auth',
25 'django.contrib.contenttypes',
26 'django.contrib.sessions',
27 'django.contrib.messages',
28 'django.contrib.staticfiles',
29 'corsheaders',
30 'rest_framework_simplejwt.token_blacklist',
31 'rest_framework',
32 'rest_framework.authtoken',
33 'rest_auth',
34 'TripApp',
35 'api'
36]
37
38# added corsheaders middleware below
39MIDDLEWARE = [
40 'django.middleware.security.SecurityMiddleware',
41 'django.contrib.sessions.middleware.SessionMiddleware',
42 'corsheaders.middleware.CorsMiddleware',
43 'django.middleware.common.CommonMiddleware',
44 'django.middleware.csrf.CsrfViewMiddleware',
45 'django.contrib.auth.middleware.AuthenticationMiddleware',
46 'django.contrib.messages.middleware.MessageMiddleware',
47 'django.middleware.clickjacking.XFrameOptionsMiddleware',
48]
49
50# **Dont forget to add your client's address to the CORS whitelist. This will make sure the server accepts request from
51# the specified source only
52CORS_ORIGIN_WHITELIST = [
53 "http://localhost:8080",
54 "http://127.0.0.1:8000"
55]
56
57# allow all requests containing any of the default headers(as in django docs) or content-type header
58CORS_ALLOW_HEADERS = default_headers + (
59 'contenttype',
60)
61
62CORS_ORIGIN_ALLOW_ALL=True
63
64# CORS_ORIGIN_ALLOW_ALL = True
65
66ROOT_URLCONF = 'TripApp.urls'
67
68TEMPLATES = [
69 {
70 'BACKEND': 'django.template.backends.django.DjangoTemplates',
71 'DIRS': [],
72 'APP_DIRS': True,
73 'OPTIONS': {
74 'context_processors': [
75 'django.template.context_processors.debug',
76 'django.template.context_processors.request',
77 'django.contrib.auth.context_processors.auth',
78 'django.contrib.messages.context_processors.messages',
79 ],
80 },
81 },
82]
83
84WSGI_APPLICATION = 'TripApp.wsgi.application'
85# Database
86# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
87
88# **Don't forget to enter your database details below
89DATABASES = {
90 'default': {
91 'ENGINE': 'django.db.backends.sqlite3',
92 'NAME': 'mydatabase',
93 }
94}
95
96
97
98# Password validation
99# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
100
101AUTH_PASSWORD_VALIDATORS = [
102 {
103 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
104 },
105 {
106 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
107 },
108 {
109 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
110 },
111 {
112 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
113 },
114]
115
116
117# Internationalization
118# https://docs.djangoproject.com/en/2.1/topics/i18n/
119
120LANGUAGE_CODE = 'en-us'
121
122TIME_ZONE = 'UTC'
123
124USE_I18N = True
125
126USE_L10N = True
127
128USE_TZ = True
129
130STATIC_URL = '/static/'
131
132# added simplejwt plugin as default authentication class below
133REST_FRAMEWORK = {
134 'DEFAULT_AUTHENTICATION_CLASSES': (
135 'rest_framework_simplejwt.authentication.JWTAuthentication',
136 )
137}