|
| 1 | +""" |
| 2 | +Django settings for QuestionTime project. |
| 3 | +
|
| 4 | +Generated by 'django-admin startproject' using Django 3.0.1. |
| 5 | +
|
| 6 | +For more information on this file, see |
| 7 | +https://docs.djangoproject.com/en/3.0/topics/settings/ |
| 8 | +
|
| 9 | +For the full list of settings and their values, see |
| 10 | +https://docs.djangoproject.com/en/3.0/ref/settings/ |
| 11 | +""" |
| 12 | + |
| 13 | +import os |
| 14 | +import dj_database_url |
| 15 | + |
| 16 | +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
| 17 | +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 18 | + |
| 19 | +# Quick-start development settings - unsuitable for production |
| 20 | +# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ |
| 21 | + |
| 22 | + |
| 23 | +# SECURITY WARNING: keep the secret key used in production secret! |
| 24 | +SECRET_KEY = os.environ.get('SECRET_KEY', '') |
| 25 | + |
| 26 | +# SECURITY WARNING: don't run with debug turned on in production! |
| 27 | +DEBUG = os.environ.get('DEBUG', '') |
| 28 | + |
| 29 | +if not DEBUG: |
| 30 | + try: |
| 31 | + import local_settings as ls |
| 32 | + |
| 33 | + SECRET_KEY = ls.SECRET_KEY |
| 34 | + DEBUG = ls.DEBUG |
| 35 | + except ImportError: |
| 36 | + pass |
| 37 | + |
| 38 | +ALLOWED_HOSTS = ['questiontimey.herokuapp.com', 'localhost', '*'] |
| 39 | + |
| 40 | +# Custom User Model |
| 41 | +AUTH_USER_MODEL = 'users.CustomUser' |
| 42 | + |
| 43 | +# Application definition |
| 44 | + |
| 45 | +INSTALLED_APPS = [ |
| 46 | + 'django.contrib.admin', |
| 47 | + 'django.contrib.auth', |
| 48 | + 'django.contrib.contenttypes', |
| 49 | + 'django.contrib.sessions', |
| 50 | + 'django.contrib.messages', |
| 51 | + 'django.contrib.staticfiles', |
| 52 | + 'django.contrib.sites', |
| 53 | + |
| 54 | + 'rest_framework', |
| 55 | + 'rest_framework.authtoken', |
| 56 | + |
| 57 | + 'allauth', |
| 58 | + 'allauth.account', |
| 59 | + 'allauth.socialaccount', |
| 60 | + |
| 61 | + 'rest_auth', |
| 62 | + 'rest_auth.registration', |
| 63 | + |
| 64 | + 'django_registration', |
| 65 | + |
| 66 | + 'crispy_forms', |
| 67 | + 'webpack_loader', |
| 68 | + |
| 69 | + 'users', |
| 70 | + 'questions', |
| 71 | +] |
| 72 | + |
| 73 | +MIDDLEWARE = [ |
| 74 | + 'django.middleware.security.SecurityMiddleware', |
| 75 | + 'whitenoise.middleware.WhiteNoiseMiddleware', |
| 76 | + 'django.contrib.sessions.middleware.SessionMiddleware', |
| 77 | + 'django.middleware.common.CommonMiddleware', |
| 78 | + 'django.middleware.csrf.CsrfViewMiddleware', |
| 79 | + 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 80 | + 'django.contrib.messages.middleware.MessageMiddleware', |
| 81 | + 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
| 82 | +] |
| 83 | + |
| 84 | +ROOT_URLCONF = 'QuestionTime.urls' |
| 85 | + |
| 86 | +TEMPLATES = [ |
| 87 | + { |
| 88 | + 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 89 | + 'DIRS': [os.path.join(BASE_DIR, 'templates')], |
| 90 | + 'APP_DIRS': True, |
| 91 | + 'OPTIONS': { |
| 92 | + 'context_processors': [ |
| 93 | + 'django.template.context_processors.debug', |
| 94 | + 'django.template.context_processors.request', |
| 95 | + 'django.contrib.auth.context_processors.auth', |
| 96 | + 'django.contrib.messages.context_processors.messages', |
| 97 | + ], |
| 98 | + }, |
| 99 | + }, |
| 100 | +] |
| 101 | + |
| 102 | +WSGI_APPLICATION = 'QuestionTime.wsgi.application' |
| 103 | + |
| 104 | +# Database |
| 105 | +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases |
| 106 | + |
| 107 | +DATABASES = { |
| 108 | + 'default': { |
| 109 | + 'ENGINE': 'django.db.backends.sqlite3', |
| 110 | + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +if not DEBUG: |
| 115 | + db_from_env = dj_database_url.config(conn_max_age=500) |
| 116 | + DATABASES['default'].update(db_from_env) |
| 117 | + |
| 118 | +# Password validation |
| 119 | +# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators |
| 120 | + |
| 121 | +AUTH_PASSWORD_VALIDATORS = [ |
| 122 | + { |
| 123 | + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
| 124 | + }, |
| 125 | + { |
| 126 | + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
| 127 | + }, |
| 128 | + { |
| 129 | + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
| 130 | + }, |
| 131 | + { |
| 132 | + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
| 133 | + }, |
| 134 | +] |
| 135 | + |
| 136 | +if not DEBUG: |
| 137 | + SESSION_COOKIE_SECURE = True |
| 138 | + CSRF_COOKIE_SECURE = True |
| 139 | + |
| 140 | +# Internationalization |
| 141 | +# https://docs.djangoproject.com/en/3.0/topics/i18n/ |
| 142 | + |
| 143 | +LANGUAGE_CODE = 'en-us' |
| 144 | + |
| 145 | +TIME_ZONE = 'UTC' |
| 146 | + |
| 147 | +USE_I18N = True |
| 148 | + |
| 149 | +USE_L10N = True |
| 150 | + |
| 151 | +USE_TZ = True |
| 152 | + |
| 153 | +# Static files (CSS, JavaScript, Images) |
| 154 | +# https://docs.djangoproject.com/en/3.0/howto/static-files/ |
| 155 | + |
| 156 | +STATIC_URL = '/static/' |
| 157 | +STATICFILES_DIRS = [ |
| 158 | + os.path.join(BASE_DIR, "static"), |
| 159 | + os.path.join(BASE_DIR, "frontend/dist"), |
| 160 | +] |
| 161 | +# absolute to the directory where collectstatic will collect static files for deployment |
| 162 | +if not DEBUG: |
| 163 | + STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') |
| 164 | + STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' |
| 165 | + |
| 166 | +# django-crispy-forms |
| 167 | +CRISPY_TEMPLATE_PACK = 'bootstrap4' |
| 168 | + |
| 169 | +# django.contrib.sites |
| 170 | +SITE_ID = 1 |
| 171 | + |
| 172 | +# django-allauth |
| 173 | +ACCOUNT_EMAIL_VERIFICATION = 'none' |
| 174 | +ACCOUNT_EMAIL_REQUIRED = True |
| 175 | + |
| 176 | +LOGIN_URL = 'accounts/login/' |
| 177 | +LOGIN_REDIRECT_URL = '/' |
| 178 | +LOGOUT_REDIRECT_URL = '/' |
| 179 | + |
| 180 | +# Django-REST-Framework |
| 181 | +REST_FRAMEWORK = { |
| 182 | + 'DEFAULT_AUTHENTICATION_CLASSES': ( |
| 183 | + 'rest_framework.authentication.TokenAuthentication', |
| 184 | + 'rest_framework.authentication.SessionAuthentication', |
| 185 | + ), |
| 186 | + 'DEFAULT_PERMISSION_CLASSES': ( |
| 187 | + 'rest_framework.permissions.IsAuthenticated', |
| 188 | + ), |
| 189 | + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', |
| 190 | + 'PAGE_SIZE': 3 |
| 191 | +} |
| 192 | + |
| 193 | +WEBPACK_LOADER = { |
| 194 | + 'DEFAULT': { |
| 195 | + 'BUNDLE_DIR_NAME': 'dist/', |
| 196 | + 'STATS_FILE': os.path.join(BASE_DIR, 'frontend', 'webpack-stats.json'), |
| 197 | + } |
| 198 | +} |
0 commit comments