· 7 years ago · Jan 09, 2019, 07:38 PM
1"""
2Django settings for DjReactTuto project.
3
4Generated by 'django-admin startproject' using Django 2.1.4.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/2.1/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/2.1/ref/settings/
11"""
12
13import os
14import django_heroku
15from str2bool import str2bool
16
17# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
18BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19
20
21# Quick-start development settings - unsuitable for production
22# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
23
24# SECURITY WARNING: keep the secret key used in production secret!
25SECRET_KEY = os.getenv('SECRET_KEY', '')
26
27# SECURITY WARNING: don't run with debug turned on in production!
28DEBUG = str2bool(os.getenv('DEBUG', 'True'))
29
30ALLOWED_HOSTS = [
31 '*',
32]
33
34
35# Application definition
36
37INSTALLED_APPS = [
38 'django.contrib.admin',
39 'django.contrib.auth',
40 'django.contrib.contenttypes',
41 'django.contrib.sessions',
42 'django.contrib.messages',
43 'django.contrib.staticfiles',
44
45 'django.contrib.sites',
46 'allauth',
47 'allauth.account',
48 'allauth.socialaccount',
49 'corsheaders',
50
51 'rest_auth',
52 'rest_auth.registration',
53
54 'rest_framework',
55 'rest_framework.authtoken',
56
57
58 'articles'
59]
60
61SITE_ID = 1
62
63
64MIDDLEWARE = [
65 'corsheaders.middleware.CorsMiddleware',
66 'django.middleware.security.SecurityMiddleware',
67 'whitenoise.middleware.WhiteNoiseMiddleware',
68 'django.contrib.sessions.middleware.SessionMiddleware',
69 'django.middleware.common.CommonMiddleware',
70 'django.middleware.csrf.CsrfViewMiddleware',
71 'django.contrib.auth.middleware.AuthenticationMiddleware',
72 'django.contrib.messages.middleware.MessageMiddleware',
73 'django.middleware.clickjacking.XFrameOptionsMiddleware',
74]
75
76ROOT_URLCONF = 'djreact.urls'
77
78TEMPLATES = [
79 {
80 'BACKEND': 'django.template.backends.django.DjangoTemplates',
81 'DIRS': [os.path.join(BASE_DIR, 'build')],
82 'APP_DIRS': True,
83 'OPTIONS': {
84 'context_processors': [
85 'django.template.context_processors.debug',
86 'django.template.context_processors.request',
87 'django.contrib.auth.context_processors.auth',
88 'django.contrib.messages.context_processors.messages',
89 ],
90 },
91 },
92]
93
94WSGI_APPLICATION = 'djreact.wsgi.application'
95
96
97# Database
98# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
99
100DATABASES = {
101 'default': {
102 'ENGINE': os.getenv('DB_ENGINE', 'django.db.backends.sqlite3'),
103 'NAME': os.getenv('DB_NAME', 'db.sqlite3'),
104 'USER': os.getenv('DB_USER', None),
105 'PASSWORD': os.getenv('DB_PASSWORD', None),
106 'HOST': os.getenv('DB_HOST', None),
107 'PORT': os.getenv('DB_PORT', None),
108 }
109}
110
111
112# Password validation
113# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
114
115AUTH_PASSWORD_VALIDATORS = [
116 {
117 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
118 },
119 {
120 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
121 },
122 {
123 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
124 },
125 {
126 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
127 },
128]
129
130
131# Internationalization
132# https://docs.djangoproject.com/en/2.1/topics/i18n/
133
134LANGUAGE_CODE = 'en-us'
135
136TIME_ZONE = 'UTC'
137
138USE_I18N = True
139
140USE_L10N = True
141
142USE_TZ = True
143
144
145# Static files (CSS, JavaScript, Images)
146# https://docs.djangoproject.com/en/2.1/howto/static-files/
147
148STATIC_URL = '/static/'
149STATICFILES_DIRS = [
150 os.path.join(BASE_DIR, 'build/static'),
151]
152STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
153
154# STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
155STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
156
157# Rest Framework settings
158
159REST_FRAMEWORK = {
160 # Use Django's standard `django.contrib.auth` permissions,
161 # or allow read-only access for unauthenticated users.
162 'DEFAULT_PERMISSION_CLASSES': [
163 # 'rest_framework.permissions.AllowAny',
164 # 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
165 ],
166 'DEFAULT_AUTHENTICATION_CLASSES': [
167 'rest_framework.authentication.TokenAuthentication',
168 ]
169}
170
171CORS_ORIGIN_ALLOW_ALL = True
172
173
174# AllAuth
175ACCOUNT_EMAIL_VERIFICATION = 'none'
176ACCOUNT_AUTHENTICATION_METHOD = 'username'
177ACCOUNT_EMAIL_REQUIRED = False
178
179
180# Log 500 Error Config
181ADMIN = [
182 ('Admin', 'admin@gmail.com'),
183]
184
185
186django_heroku.settings(locals())