· 4 years ago · Aug 29, 2021, 01:44 PM
1"""
2Django settings for core project.
3
4Generated by 'django-admin startproject' using Django 3.2.4.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/3.2/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/3.2/ref/settings/
11"""
12
13import os
14import django_heroku
15import dj_database_url
16import dotenv
17
18from pathlib import Path
19from datetime import timedelta
20
21# Build paths inside the project like this: BASE_DIR / 'subdir'.
22BASE_DIR = Path(__file__).resolve().parent.parent
23
24dotenv_file = os.path.join(BASE_DIR, ".env")
25
26if os.path.isfile(dotenv_file):
27 dotenv.load_dotenv(dotenv_file)
28
29# Quick-start development settings - unsuitable for production
30# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
31
32# env =environ.Env()
33
34# environ.Env.read_env()
35
36# SECURITY WARNING: keep the secret key used in production secret!
37
38SECRET_KEY =''
39
40# SECURITY WARNING: don't run with debug turned on in production!
41DEBUG = True
42
43ALLOWED_HOSTS = []
44
45
46# Application definition
47
48INSTALLED_APPS = [
49 'django.contrib.admin',
50 'django.contrib.auth',
51 'django.contrib.contenttypes',
52 'django.contrib.sessions',
53 'django.contrib.messages',
54 'django.contrib.staticfiles',
55
56 # local
57 'blog_api',
58 'blog',
59 'users',
60
61 # 3rd party
62 'rest_framework',
63 'corsheaders',
64 'rest_framework_simplejwt.token_blacklist',
65]
66
67MIDDLEWARE = [
68 'django.middleware.security.SecurityMiddleware',
69 'django.contrib.sessions.middleware.SessionMiddleware',
70 'corsheaders.middleware.CorsMiddleware',
71 'django.middleware.common.CommonMiddleware',
72 'django.middleware.csrf.CsrfViewMiddleware',
73 'django.contrib.auth.middleware.AuthenticationMiddleware',
74 'django.contrib.messages.middleware.MessageMiddleware',
75 'django.middleware.clickjacking.XFrameOptionsMiddleware',
76]
77
78ROOT_URLCONF = 'core.urls'
79
80TEMPLATES = [
81 {
82 'BACKEND': 'django.template.backends.django.DjangoTemplates',
83 'DIRS': [BASE_DIR / 'templates'],
84 'APP_DIRS': True,
85 'OPTIONS': {
86 'context_processors': [
87 'django.template.context_processors.debug',
88 'django.template.context_processors.request',
89 'django.contrib.auth.context_processors.auth',
90 'django.contrib.messages.context_processors.messages',
91 ],
92 },
93 },
94]
95
96WSGI_APPLICATION = 'core.wsgi.application'
97
98
99# Database
100# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
101
102# DATABASES = {
103# 'default': {
104# 'ENGINE': 'django.db.backends.sqlite3',
105# 'NAME': BASE_DIR / 'db.sqlite3',
106# }
107# }
108
109DATABASES = {}
110DATABASES['default'] = dj_database_url.config(conn_max_age=600)
111
112
113# Password validation
114# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
115
116AUTH_PASSWORD_VALIDATORS = [
117 {
118 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
119 },
120 {
121 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
122 },
123 {
124 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
125 },
126 {
127 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
128 },
129]
130
131
132# Internationalization
133# https://docs.djangoproject.com/en/3.2/topics/i18n/
134
135LANGUAGE_CODE = 'en-us'
136
137TIME_ZONE = 'UTC'
138
139USE_I18N = True
140
141USE_L10N = True
142
143USE_TZ = True
144
145AUTH_USER_MODEL='users.CustomUser'
146
147
148# Static files (CSS, JavaScript, Images)
149# https://docs.djangoproject.com/en/3.2/howto/static-files/
150
151STATIC_URL = '/static/'
152
153MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
154MEDIA_URL = '/media/'
155
156REST_FRAMEWORK = {
157 'DEFAULT_PERMISSION_CLASSES': ['rest_framework.permissions.AllowAny'],
158 'DEFAULT_AUTHENTICATION_CLASSES':['rest_framework_simplejwt.authentication.JWTAuthentication'],
159 'DEFAULT_SCHEMA_CLASS':'rest_framework.schemas.coreapi.AutoSchema',
160}
161
162# Default primary key field type
163# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
164
165DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
166
167CORS_ORIGIN_WHITELIST = [
168 'http://localhost:3000'
169]
170
171CORS_ORIGIN_ALLOW_ALL = True
172
173SIMPLE_JWT = {
174 'ACCESS_TOKEN_LIFETIME': timedelta(hours=1),
175 'REFRESH_TOKEN_LIFETIME': timedelta(days=2),
176 'ROTATE_REFRESH_TOKENS': False,
177 'BLACKLIST_AFTER_ROTATION': True,
178 'UPDATE_LAST_LOGIN': False,
179
180 'ALGORITHM': 'HS256',
181 'SIGNING_KEY': SECRET_KEY,
182 'VERIFYING_KEY': None,
183 'AUDIENCE': None,
184 'ISSUER': None,
185
186 'AUTH_HEADER_TYPES': ('JWT',),
187 'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
188 'USER_ID_FIELD': 'id',
189 'USER_ID_CLAIM': 'user_id',
190 'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule',
191
192 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
193 'TOKEN_TYPE_CLAIM': 'token_type',
194
195 'JTI_CLAIM': 'jti',
196
197 'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
198 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
199 'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
200}
201
202
203django_heroku.settings(locals())
204
205options = DATABASES['default'].get('OPTIONS',{})
206options.pop('sslmode', None)