base.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. """
  2. Django settings for temp project.
  3. Generated by 'django-admin startproject' using Django 1.10.5.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/3.2/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/3.2/ref/settings/
  8. """
  9. import os
  10. import dj_database_url
  11. # Build paths inside the project like this: os.path.join(PROJECT_DIR, ...)
  12. PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  13. BASE_DIR = os.path.dirname(PROJECT_DIR)
  14. # Quick-start development settings - unsuitable for production
  15. # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
  16. # SECURITY WARNING: keep the secret key used in production secret!
  17. SECRET_KEY = "c6u0-9c!7nilj_ysatsda0(f@e_2mws2f!6m0n^o*4#*q#kzp)"
  18. # SECURITY WARNING: don't run with debug turned on in production!
  19. DEBUG = True
  20. ALLOWED_HOSTS = []
  21. # Uncomment (and adjust as appropriate) to enable django-debug-toolbar
  22. # INTERNAL_IPS = [
  23. # '127.0.0.1',
  24. # ]
  25. # Application definition
  26. INSTALLED_APPS = [
  27. "bakerydemo.base",
  28. "bakerydemo.blog",
  29. "bakerydemo.breads",
  30. "bakerydemo.locations",
  31. "bakerydemo.recipes",
  32. "bakerydemo.search",
  33. "wagtail.embeds",
  34. "wagtail.sites",
  35. "wagtail.users",
  36. "wagtail.snippets",
  37. "wagtail.documents",
  38. "wagtail.images",
  39. "wagtail.search",
  40. "wagtail.admin",
  41. "wagtail.api.v2",
  42. "wagtail.locales",
  43. "wagtail.contrib.forms",
  44. "wagtail.contrib.redirects",
  45. "wagtail.contrib.routable_page",
  46. "wagtail.contrib.table_block",
  47. "wagtail.contrib.typed_table_block",
  48. "wagtail.contrib.search_promotions",
  49. "wagtail.contrib.settings",
  50. "wagtail.contrib.simple_translation",
  51. "wagtail.contrib.styleguide",
  52. "wagtail",
  53. "rest_framework",
  54. "modelcluster",
  55. "taggit",
  56. "wagtailfontawesomesvg",
  57. # Uncomment to enable django-debug-toolbar
  58. # "debug_toolbar",
  59. "django_extensions",
  60. "django.contrib.admin",
  61. "django.contrib.auth",
  62. "django.contrib.contenttypes",
  63. "django.contrib.sessions",
  64. "django.contrib.messages",
  65. "django.contrib.staticfiles",
  66. "django.contrib.sitemaps",
  67. ]
  68. MIDDLEWARE = [
  69. # Uncomment to enable django-debug-toolbar
  70. # "debug_toolbar.middleware.DebugToolbarMiddleware",
  71. "django.middleware.security.SecurityMiddleware",
  72. "django.contrib.sessions.middleware.SessionMiddleware",
  73. "django.middleware.common.CommonMiddleware",
  74. "django.middleware.csrf.CsrfViewMiddleware",
  75. "django.contrib.auth.middleware.AuthenticationMiddleware",
  76. "django.contrib.messages.middleware.MessageMiddleware",
  77. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  78. "wagtail.contrib.redirects.middleware.RedirectMiddleware",
  79. ]
  80. DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
  81. ROOT_URLCONF = "bakerydemo.urls"
  82. TEMPLATES = [
  83. {
  84. "BACKEND": "django.template.backends.django.DjangoTemplates",
  85. "DIRS": [
  86. "bakerydemo/templates",
  87. ],
  88. "APP_DIRS": True,
  89. "OPTIONS": {
  90. "context_processors": [
  91. "django.template.context_processors.debug",
  92. "django.template.context_processors.request",
  93. "django.contrib.auth.context_processors.auth",
  94. "django.contrib.messages.context_processors.messages",
  95. "wagtail.contrib.settings.context_processors.settings",
  96. ],
  97. },
  98. },
  99. ]
  100. WSGI_APPLICATION = "bakerydemo.wsgi.application"
  101. # Database
  102. # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
  103. if "DATABASE_URL" in os.environ:
  104. DATABASES = {"default": dj_database_url.config(conn_max_age=500)}
  105. else:
  106. DATABASES = {
  107. "default": {
  108. "ENGINE": "django.db.backends.sqlite3",
  109. "NAME": os.path.join(BASE_DIR, "bakerydemodb"),
  110. }
  111. }
  112. # Password validation
  113. # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
  114. AUTH_PASSWORD_VALIDATORS = [
  115. {
  116. "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  117. },
  118. {
  119. "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
  120. },
  121. {
  122. "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
  123. },
  124. {
  125. "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
  126. },
  127. ]
  128. # Internationalization
  129. # https://docs.djangoproject.com/en/3.2/topics/i18n/
  130. LANGUAGE_CODE = "en-us"
  131. TIME_ZONE = "UTC"
  132. USE_I18N = True
  133. USE_L10N = True
  134. USE_TZ = True
  135. # Static files (CSS, JavaScript, Images)
  136. # https://docs.djangoproject.com/en/3.2/howto/static-files/
  137. STATICFILES_FINDERS = [
  138. "django.contrib.staticfiles.finders.FileSystemFinder",
  139. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  140. ]
  141. STATICFILES_DIRS = [
  142. os.path.join(PROJECT_DIR, "static"),
  143. ]
  144. STATIC_ROOT = os.path.join(PROJECT_DIR, "collect_static")
  145. STATIC_URL = "/static/"
  146. MEDIA_ROOT = os.path.join(PROJECT_DIR, "media")
  147. MEDIA_URL = "/media/"
  148. # Override in local settings or replace with your own key. Please don't use our demo key in production!
  149. GOOGLE_MAP_API_KEY = "AIzaSyD31CT9P9KxvNUJOwDq2kcFEIG8ADgaFgw"
  150. # Use Elasticsearch as the search backend for extra performance and better search results
  151. WAGTAILSEARCH_BACKENDS = {
  152. "default": {
  153. "BACKEND": "wagtail.search.backends.database",
  154. "INDEX": "bakerydemo",
  155. },
  156. }
  157. # Wagtail settings
  158. WAGTAIL_SITE_NAME = "The Wagtail Bakery"
  159. WAGTAIL_I18N_ENABLED = True
  160. WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [
  161. ("en", "English"),
  162. ("de", "Deutsch"),
  163. ("ar", "العربيّة"),
  164. ]
  165. WAGTAILIMAGES_AVIF_QUALITY = 60
  166. ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "changeme")
  167. # Content Security policy settings
  168. # http://django-csp.readthedocs.io/en/latest/configuration.html
  169. # Only enable CSP when enabled through environment variables.
  170. if "CSP_DEFAULT_SRC" in os.environ:
  171. MIDDLEWARE.append("csp.middleware.CSPMiddleware")
  172. # Only report violations, don't enforce policy
  173. CSP_REPORT_ONLY = True
  174. # The “special” source values of 'self', 'unsafe-inline', 'unsafe-eval', and 'none' must be quoted!
  175. # e.g.: CSP_DEFAULT_SRC = "'self'" Without quotes they will not work as intended.
  176. CSP_DEFAULT_SRC = os.environ.get("CSP_DEFAULT_SRC").split(",")
  177. if "CSP_SCRIPT_SRC" in os.environ:
  178. CSP_SCRIPT_SRC = os.environ.get("CSP_SCRIPT_SRC").split(",")
  179. if "CSP_STYLE_SRC" in os.environ:
  180. CSP_STYLE_SRC = os.environ.get("CSP_STYLE_SRC").split(",")
  181. if "CSP_IMG_SRC" in os.environ:
  182. CSP_IMG_SRC = os.environ.get("CSP_IMG_SRC").split(",")
  183. if "CSP_CONNECT_SRC" in os.environ:
  184. CSP_CONNECT_SRC = os.environ.get("CSP_CONNECT_SRC").split(",")
  185. if "CSP_FONT_SRC" in os.environ:
  186. CSP_FONT_SRC = os.environ.get("CSP_FONT_SRC").split(",")
  187. if "CSP_BASE_URI" in os.environ:
  188. CSP_BASE_URI = os.environ.get("CSP_BASE_URI").split(",")
  189. if "CSP_OBJECT_SRC" in os.environ:
  190. CSP_OBJECT_SRC = os.environ.get("CSP_OBJECT_SRC").split(",")