|
| 1 | +from pathlib import Path |
| 2 | +import os |
| 3 | +import dj_database_url |
| 4 | +from django_storage_url import dsn_configured_storage_class |
| 5 | + |
| 6 | +# Build paths inside the project like this: BASE_DIR / 'subdir'. |
| 7 | +BASE_DIR = Path(__file__).resolve().parent.parent |
| 8 | + |
| 9 | + |
| 10 | +# SECURITY WARNING: keep the secret key used in production secret! |
| 11 | +SECRET_KEY = os.environ.get('SECRET_KEY', '<a string of random characters>') |
| 12 | + |
| 13 | +# SECURITY WARNING: don't run with debug turned on in production! |
| 14 | +DEBUG = os.environ.get('DJANGO_DEBUG') == "True" |
| 15 | + |
| 16 | +DIVIO_DOMAIN = os.environ.get('DOMAIN', '') |
| 17 | +DIVIO_DOMAIN_ALIASES = [ |
| 18 | + d.strip() |
| 19 | + for d in os.environ.get('DOMAIN_ALIASES', '').split(',') |
| 20 | + if d.strip() |
| 21 | +] |
| 22 | +ALLOWED_HOSTS = [DIVIO_DOMAIN] + DIVIO_DOMAIN_ALIASES |
| 23 | + |
| 24 | +# Redirect to HTTPS by default, unless explicitly disabled |
| 25 | +SECURE_SSL_REDIRECT = os.environ.get('SECURE_SSL_REDIRECT') != "False" |
| 26 | + |
| 27 | +X_FRAME_OPTIONS = 'SAMEORIGIN' |
| 28 | + |
| 29 | + |
| 30 | +# Application definition |
| 31 | + |
| 32 | +INSTALLED_APPS = [ |
| 33 | + 'quickstart', |
| 34 | + |
| 35 | + # optional, but used in most projects |
| 36 | + 'djangocms_admin_style', |
| 37 | + |
| 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 | + 'django.contrib.sites', |
| 45 | + |
| 46 | + # key django CMS modules |
| 47 | + 'cms', |
| 48 | + 'menus', |
| 49 | + 'treebeard', |
| 50 | + 'sekizai', |
| 51 | + |
| 52 | + # Django Filer - optional, but used in most projects |
| 53 | + 'filer', |
| 54 | + 'easy_thumbnails', |
| 55 | + |
| 56 | + # the default CKEditor - optional, but used in most projects |
| 57 | + 'djangocms_text_ckeditor', |
| 58 | + |
| 59 | + # some content plugins - optional, but used in most projects |
| 60 | + 'djangocms_file', |
| 61 | + 'djangocms_icon', |
| 62 | + 'djangocms_link', |
| 63 | + 'djangocms_picture', |
| 64 | + 'djangocms_style', |
| 65 | + 'djangocms_googlemap', |
| 66 | + 'djangocms_video', |
| 67 | + |
| 68 | + # optional django CMS Bootstrap 4 modules |
| 69 | + 'djangocms_bootstrap4', |
| 70 | + 'djangocms_bootstrap4.contrib.bootstrap4_alerts', |
| 71 | + 'djangocms_bootstrap4.contrib.bootstrap4_badge', |
| 72 | + 'djangocms_bootstrap4.contrib.bootstrap4_card', |
| 73 | + 'djangocms_bootstrap4.contrib.bootstrap4_carousel', |
| 74 | + 'djangocms_bootstrap4.contrib.bootstrap4_collapse', |
| 75 | + 'djangocms_bootstrap4.contrib.bootstrap4_content', |
| 76 | + 'djangocms_bootstrap4.contrib.bootstrap4_grid', |
| 77 | + 'djangocms_bootstrap4.contrib.bootstrap4_jumbotron', |
| 78 | + 'djangocms_bootstrap4.contrib.bootstrap4_link', |
| 79 | + 'djangocms_bootstrap4.contrib.bootstrap4_listgroup', |
| 80 | + 'djangocms_bootstrap4.contrib.bootstrap4_media', |
| 81 | + 'djangocms_bootstrap4.contrib.bootstrap4_picture', |
| 82 | + 'djangocms_bootstrap4.contrib.bootstrap4_tabs', |
| 83 | + 'djangocms_bootstrap4.contrib.bootstrap4_utilities', |
| 84 | +] |
| 85 | + |
| 86 | +MIDDLEWARE = [ |
| 87 | + 'django.middleware.security.SecurityMiddleware', |
| 88 | + 'whitenoise.middleware.WhiteNoiseMiddleware', |
| 89 | + 'django.contrib.sessions.middleware.SessionMiddleware', |
| 90 | + 'django.middleware.common.CommonMiddleware', |
| 91 | + 'django.middleware.csrf.CsrfViewMiddleware', |
| 92 | + 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 93 | + 'django.contrib.messages.middleware.MessageMiddleware', |
| 94 | + 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
| 95 | + 'django.middleware.locale.LocaleMiddleware', |
| 96 | + |
| 97 | + 'cms.middleware.user.CurrentUserMiddleware', |
| 98 | + 'cms.middleware.page.CurrentPageMiddleware', |
| 99 | + 'cms.middleware.toolbar.ToolbarMiddleware', |
| 100 | + 'cms.middleware.language.LanguageCookieMiddleware', |
| 101 | +] |
| 102 | + |
| 103 | +ROOT_URLCONF = 'quickstart.urls' |
| 104 | + |
| 105 | +TEMPLATES = [ |
| 106 | + { |
| 107 | + 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 108 | + 'DIRS': [], |
| 109 | + 'APP_DIRS': True, |
| 110 | + 'OPTIONS': { |
| 111 | + 'context_processors': [ |
| 112 | + 'django.template.context_processors.debug', |
| 113 | + 'django.template.context_processors.request', |
| 114 | + 'django.contrib.auth.context_processors.auth', |
| 115 | + 'django.contrib.messages.context_processors.messages', |
| 116 | + 'django.template.context_processors.media', |
| 117 | + 'django.template.context_processors.csrf', |
| 118 | + 'django.template.context_processors.tz', |
| 119 | + 'django.template.context_processors.i18n', |
| 120 | + |
| 121 | + 'cms.context_processors.cms_settings', |
| 122 | + 'sekizai.context_processors.sekizai', |
| 123 | + |
| 124 | + ], |
| 125 | + }, |
| 126 | + }, |
| 127 | +] |
| 128 | + |
| 129 | +CMS_TEMPLATES = [ |
| 130 | + # a minimal template to get started with |
| 131 | + ('minimal.html', 'Minimal template'), |
| 132 | + |
| 133 | + # optional templates that extend base.html, to be used with Bootstrap 4 |
| 134 | + ('page.html', 'Page'), |
| 135 | + ('feature.html', 'Page with Feature') |
| 136 | +] |
| 137 | + |
| 138 | +WSGI_APPLICATION = 'quickstart.wsgi.application' |
| 139 | + |
| 140 | + |
| 141 | +# Database |
| 142 | +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases |
| 143 | + |
| 144 | +# Configure database using DATABASE_URL; fall back to sqlite in memory when no |
| 145 | +# environment variable is available, e.g. during Docker build |
| 146 | +DATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite://:memory:') |
| 147 | + |
| 148 | +DATABASES = {'default': dj_database_url.parse(DATABASE_URL)} |
| 149 | + |
| 150 | + |
| 151 | +# Password validation |
| 152 | +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators |
| 153 | + |
| 154 | +AUTH_PASSWORD_VALIDATORS = [ |
| 155 | + { |
| 156 | + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
| 157 | + }, |
| 158 | + { |
| 159 | + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
| 160 | + }, |
| 161 | + { |
| 162 | + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
| 163 | + }, |
| 164 | + { |
| 165 | + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
| 166 | + }, |
| 167 | +] |
| 168 | + |
| 169 | + |
| 170 | +# Internationalization |
| 171 | +# https://docs.djangoproject.com/en/3.1/topics/i18n/ |
| 172 | + |
| 173 | +LANGUAGE_CODE = 'en' |
| 174 | + |
| 175 | +LANGUAGES = [ |
| 176 | + ('en', 'English'), |
| 177 | +] |
| 178 | + |
| 179 | +TIME_ZONE = 'UTC' |
| 180 | + |
| 181 | +USE_I18N = True |
| 182 | + |
| 183 | +USE_L10N = True |
| 184 | + |
| 185 | +USE_TZ = True |
| 186 | + |
| 187 | + |
| 188 | +# Static files (CSS, JavaScript, Images) |
| 189 | +# https://docs.djangoproject.com/en/3.1/howto/static-files/ |
| 190 | + |
| 191 | +STATIC_URL = '/static/' |
| 192 | +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') |
| 193 | +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' |
| 194 | + |
| 195 | +# Media files |
| 196 | +# DEFAULT_FILE_STORAGE is configured using DEFAULT_STORAGE_DSN |
| 197 | + |
| 198 | +# read the setting value from the environment variable |
| 199 | +DEFAULT_STORAGE_DSN = os.environ.get('DEFAULT_STORAGE_DSN') |
| 200 | + |
| 201 | +# dsn_configured_storage_class() requires the name of the setting |
| 202 | +DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN') |
| 203 | + |
| 204 | +# Django's DEFAULT_FILE_STORAGE requires the class name |
| 205 | +DEFAULT_FILE_STORAGE = 'quickstart.settings.DefaultStorageClass' |
| 206 | + |
| 207 | +# only required for local file storage and serving, in development |
| 208 | +MEDIA_URL = 'media/' |
| 209 | +MEDIA_ROOT = os.path.join('/data/media/') |
| 210 | + |
| 211 | + |
| 212 | +SITE_ID = 1 |
0 commit comments