website/website/settings.py

151 lines
3.7 KiB
Python
Raw Normal View History

2022-06-10 09:16:13 +01:00
from pathlib import Path
2022-06-12 15:17:28 +01:00
2022-06-09 08:51:47 +01:00
import environ
2022-06-09 08:36:29 +01:00
2022-06-10 09:16:13 +01:00
BASE_DIR = Path(__file__).parent.parent
2022-06-09 08:36:29 +01:00
2022-06-12 15:17:28 +01:00
env = environ.Env(DEBUG=(bool, False), BASE_HOSTNAME=(str, "example.com"))
2022-06-09 08:36:29 +01:00
2022-06-09 08:51:47 +01:00
# Read local secrets
2022-06-12 15:17:28 +01:00
environ.Env.read_env(BASE_DIR / ".env")
2022-06-09 08:36:29 +01:00
2022-06-12 15:17:28 +01:00
DEBUG = env("DEBUG")
2022-06-09 08:36:29 +01:00
2022-06-12 15:17:28 +01:00
SECRET_KEY = env("SECRET_KEY")
2022-06-09 08:36:29 +01:00
ALLOWED_HOSTS = ["*"]
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Application definition
INSTALLED_APPS = [
2022-06-14 20:57:43 +01:00
"website.common",
2022-06-09 08:36:29 +01:00
"website.home",
"website.search",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
"wagtail.snippets",
"wagtail.documents",
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail",
"modelcluster",
"taggit",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
2022-06-09 09:03:00 +01:00
"whitenoise.runserver_nostatic",
2022-06-09 08:36:29 +01:00
"django.contrib.staticfiles",
]
MIDDLEWARE = [
2022-06-09 09:03:00 +01:00
"django.middleware.security.SecurityMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
2022-06-09 08:36:29 +01:00
"django.middleware.common.CommonMiddleware",
2022-06-09 09:03:00 +01:00
"django.contrib.sessions.middleware.SessionMiddleware",
2022-06-09 08:36:29 +01:00
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]
ROOT_URLCONF = "website.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
2022-06-10 09:16:13 +01:00
BASE_DIR / "templates",
2022-06-09 08:36:29 +01:00
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "website.wsgi.application"
2022-06-12 15:17:28 +01:00
DATABASES = {"default": env.db(default=f"sqlite:///{BASE_DIR}/db.sqlite3")}
2022-06-09 08:36:29 +01:00
CACHES = {"default": env.cache(default="dummycache://")}
2022-06-09 08:36:29 +01:00
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = "en-gb"
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
STATICFILES_DIRS = [
2022-06-10 09:16:13 +01:00
BASE_DIR / "static" / "build",
2022-06-09 08:36:29 +01:00
]
if not DEBUG:
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
2022-06-09 08:36:29 +01:00
2022-06-10 09:16:13 +01:00
STATIC_ROOT = BASE_DIR / "collected-static"
2022-06-09 08:36:29 +01:00
STATIC_URL = "/static/"
2022-06-10 09:16:13 +01:00
MEDIA_ROOT = BASE_DIR / "media"
2022-06-09 08:36:29 +01:00
MEDIA_URL = "/media/"
# Wagtail settings
WAGTAIL_SITE_NAME = "website"
# Search
# https://docs.wagtail.org/en/stable/topics/search/backends.html
WAGTAILSEARCH_BACKENDS = {
"default": {
"BACKEND": "wagtail.search.backends.database",
}
}
2022-06-12 15:17:28 +01:00
BASE_HOSTNAME = env("BASE_HOSTNAME")
2022-06-09 08:51:47 +01:00
WAGTAILADMIN_BASE_URL = f"https://{BASE_HOSTNAME}"
2022-06-13 22:43:54 +01:00
if DEBUG:
2022-06-14 22:23:44 +01:00
# Add django-browser-reload
2022-06-13 22:43:54 +01:00
INSTALLED_APPS.append("django_browser_reload")
MIDDLEWARE.append("django_browser_reload.middleware.BrowserReloadMiddleware")
2022-06-14 22:23:44 +01:00
# Add django-debug-toolbar
INSTALLED_APPS.append("debug_toolbar")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": "website.common.utils.show_toolbar_callback",
"RESULTS_CACHE_SIZE": 5,
"SHOW_COLLAPSED": True,
}