· 4 years ago · Jul 24, 2021, 12:28 PM
1#common.py we will convert it to settings.py and and put it in the same directory with wsgi.py
2
3
4#settings.py
5
6import os
7from os.path import join
8from distutils.util import strtobool
9import dj_database_url
10import datetime
11from configurations import Configuration
12
13
14BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15
16
17class Common(Configuration):
18
19 INSTALLED_APPS = (
20 'django.contrib.admin',
21 'django.contrib.auth',
22 'django.contrib.contenttypes',
23 'django.contrib.sessions',
24 'django.contrib.messages',
25 'django.contrib.staticfiles',
26
27
28 # Third party apps
29 'rest_framework', # utilities for rest apis
30 'rest_framework.authtoken', # token authentication
31 'django_filters', # for filtering rest endpoints
32 'django_q',
33 'corsheaders',
34
35 # Your apps
36 'hakeemdictionarybackend.users',
37 'hakeemdictionarybackend.dictionary',
38
39
40 )
41
42 # https://docs.djangoproject.com/en/2.0/topics/http/middleware/
43 MIDDLEWARE = (
44 'django.middleware.security.SecurityMiddleware',
45 'django.contrib.sessions.middleware.SessionMiddleware',
46 'django.middleware.common.CommonMiddleware',
47 'django.middleware.csrf.CsrfViewMiddleware',
48 'django.contrib.auth.middleware.AuthenticationMiddleware',
49 'django.contrib.messages.middleware.MessageMiddleware',
50 'django.middleware.clickjacking.XFrameOptionsMiddleware',
51 'corsheaders.middleware.CorsMiddleware',
52 )
53
54 ALLOWED_HOSTS = ["*"]
55 ROOT_URLCONF = 'hakeemdictionarybackend.urls'
56 SECRET_KEY = 'django-insecure-ttvzsnu99jd21-0$q8r4!hj%5wgqdpt-e=v0jilr$30-aj&u=s'
57 WSGI_APPLICATION = 'hakeemdictionarybackend.wsgi.application'
58
59 CORS_ORIGIN_ALLOW_ALL = True
60 # CORS_ALLOW_CREDENTIALS = False
61 # CORS_ORIGIN_WHITELIST = (
62 # # TODO - set this properly for production
63 # 'https://localhost:8000',
64 # 'http://localhost:8000',
65 # )
66
67 # Email
68 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
69
70 ADMINS = (
71 ('Author', 'a.tlimat@gmail.com'),
72 )
73
74 # Postgres
75 DATABASES = {
76 'default': {
77
78 'ENGINE': 'django.db.backends.postgresql',
79 'NAME': 'your_database_name',
80 'USER': 'postgres',
81 'PASSWORD': 'your_password',
82 'HOST': 'localhost',
83 'PORT': '5432',
84
85 }
86 }
87
88 # General
89 APPEND_SLASH = False
90 TIME_ZONE = 'America/New_York'
91 LANGUAGE_CODE = 'en-us'
92 # If you set this to False, Django will make some optimizations so as not
93 # to load the internationalization machinery.
94 USE_I18N = False
95 USE_L10N = True
96 USE_TZ = True
97 LOGIN_REDIRECT_URL = '/'
98
99 # Static files (CSS, JavaScript, Images)
100 # https://docs.djangoproject.com/en/2.0/howto/static-files/
101 STATIC_ROOT = os.path.dirname(BASE_DIR, 'static')
102 STATICFILES_DIRS = []
103 STATIC_URL = '/static/'
104 STATICFILES_FINDERS = (
105 'django.contrib.staticfiles.finders.FileSystemFinder',
106 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
107 )
108
109 # Media files
110 MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
111 MEDIA_URL = '/media/'
112
113 TEMPLATES = [
114 {
115 'BACKEND': 'django.template.backends.django.DjangoTemplates',
116 'DIRS': [BASE_DIR , 'templates'],
117 'APP_DIRS': True,
118 'OPTIONS': {
119 'context_processors': [
120 'django.template.context_processors.debug',
121 'django.template.context_processors.request',
122 'django.contrib.auth.context_processors.auth',
123 'django.contrib.messages.context_processors.messages',
124 ],
125 },
126 },
127 ]
128
129 # Set DEBUG to False as a default for safety
130 # https://docs.djangoproject.com/en/dev/ref/settings/#debug
131 DEBUG = True # strtobool(os.getenv('DJANGO_DEBUG', 'no'))
132
133 # Password Validation
134 # https://docs.djangoproject.com/en/2.0/topics/auth/passwords/#module-django.contrib.auth.password_validation
135 AUTH_PASSWORD_VALIDATORS = [
136 {
137 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
138 },
139 {
140 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
141 },
142 {
143 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
144 },
145 {
146 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
147 },
148 ]
149
150 Q_CLUSTER = {
151 'redis': {
152 'host': 'redis',
153 'port': 6379,
154 'db': 0,
155 'password': None,
156 'socket_timeout': None,
157 'charset': 'utf-8',
158 'errors': 'strict',
159 'unix_socket_path': None
160 }
161 }
162
163 JWT_AUTH = {
164 'JWT_ALLOW_REFRESH': True,
165 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=1),
166 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
167 }
168
169 # Logging
170 LOGGING = {
171 'version': 1,
172 'disable_existing_loggers': False,
173 'formatters': {
174 'django.server': {
175 '()': 'django.utils.log.ServerFormatter',
176 'format': '[%(server_time)s] %(message)s',
177 },
178 'verbose': {
179 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
180 },
181 'simple': {
182 'format': '%(levelname)s %(message)s'
183 },
184 },
185 'filters': {
186 'require_debug_true': {
187 '()': 'django.utils.log.RequireDebugTrue',
188 },
189 },
190 'handlers': {
191 'django.server': {
192 'level': 'INFO',
193 'class': 'logging.StreamHandler',
194 'formatter': 'django.server',
195 },
196 'console': {
197 'level': 'DEBUG',
198 'class': 'logging.StreamHandler',
199 'formatter': 'simple'
200 },
201 'mail_admins': {
202 'level': 'ERROR',
203 'class': 'django.utils.log.AdminEmailHandler'
204 }
205 },
206 'loggers': {
207 'django': {
208 'handlers': ['console'],
209 'propagate': True,
210 },
211 'django.server': {
212 'handlers': ['django.server'],
213 'level': 'INFO',
214 'propagate': False,
215 },
216 'django.request': {
217 'handlers': ['mail_admins', 'console'],
218 'level': 'ERROR',
219 'propagate': False,
220 },
221 'django.db.backends': {
222 'handlers': ['console'],
223 'level': 'INFO'
224 },
225 }
226 }
227
228 # Custom user app
229 AUTH_USER_MODEL = 'users.User' # you must install django-allauth
230
231 # Django Rest Framework
232 REST_FRAMEWORK = {
233 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
234 'PAGE_SIZE': int(os.getenv('DJANGO_PAGINATION_LIMIT', 10)),
235 'DATETIME_FORMAT': '%Y-%m-%dT%H:%M:%S%z',
236 'DEFAULT_RENDERER_CLASSES': (
237 'rest_framework.renderers.JSONRenderer',
238 'rest_framework.renderers.BrowsableAPIRenderer',
239 ),
240 'DEFAULT_PERMISSION_CLASSES': [
241 'rest_framework.permissions.IsAuthenticated',
242 ],
243 'DEFAULT_AUTHENTICATION_CLASSES': (
244 'rest_framework.authentication.SessionAuthentication',
245 'rest_framework.authentication.TokenAuthentication',
246 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
247 ),
248 'DEFAULT_THROTTLE_CLASSES': [
249 'rest_framework.throttling.AnonRateThrottle'
250 ],
251 'DEFAULT_THROTTLE_RATES': {'anon': '6/minute'}
252 }