base.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 this (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.modeladmin",
  49. "wagtail.contrib.search_promotions",
  50. "wagtail.contrib.settings",
  51. "wagtail.contrib.simple_translation",
  52. "wagtail.contrib.styleguide",
  53. "wagtail",
  54. "rest_framework",
  55. "modelcluster",
  56. "taggit",
  57. "wagtailfontawesomesvg",
  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. "debug_toolbar.middleware.DebugToolbarMiddleware",
  70. "django.middleware.security.SecurityMiddleware",
  71. "django.contrib.sessions.middleware.SessionMiddleware",
  72. "django.middleware.common.CommonMiddleware",
  73. "django.middleware.csrf.CsrfViewMiddleware",
  74. "django.contrib.auth.middleware.AuthenticationMiddleware",
  75. "django.contrib.messages.middleware.MessageMiddleware",
  76. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  77. "wagtail.contrib.redirects.middleware.RedirectMiddleware",
  78. ]
  79. DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
  80. ROOT_URLCONF = "bakerydemo.urls"
  81. TEMPLATES = [
  82. {
  83. "BACKEND": "django.template.backends.django.DjangoTemplates",
  84. "DIRS": [
  85. "bakerydemo/templates",
  86. ],
  87. "APP_DIRS": True,
  88. "OPTIONS": {
  89. "context_processors": [
  90. "django.template.context_processors.debug",
  91. "django.template.context_processors.request",
  92. "django.contrib.auth.context_processors.auth",
  93. "django.contrib.messages.context_processors.messages",
  94. "wagtail.contrib.settings.context_processors.settings",
  95. ],
  96. },
  97. },
  98. ]
  99. WSGI_APPLICATION = "bakerydemo.wsgi.application"
  100. # Database
  101. # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
  102. if "DATABASE_URL" in os.environ:
  103. DATABASES = {"default": dj_database_url.config(conn_max_age=500)}
  104. else:
  105. DATABASES = {
  106. "default": {
  107. "ENGINE": "django.db.backends.sqlite3",
  108. "NAME": os.path.join(BASE_DIR, "bakerydemodb"),
  109. }
  110. }
  111. # Password validation
  112. # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
  113. AUTH_PASSWORD_VALIDATORS = [
  114. {
  115. "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  116. },
  117. {
  118. "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
  119. },
  120. {
  121. "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
  122. },
  123. {
  124. "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
  125. },
  126. ]
  127. # Internationalization
  128. # https://docs.djangoproject.com/en/3.2/topics/i18n/
  129. LANGUAGE_CODE = "en-us"
  130. TIME_ZONE = "UTC"
  131. USE_I18N = True
  132. USE_L10N = True
  133. USE_TZ = True
  134. # Static files (CSS, JavaScript, Images)
  135. # https://docs.djangoproject.com/en/3.2/howto/static-files/
  136. STATICFILES_FINDERS = [
  137. "django.contrib.staticfiles.finders.FileSystemFinder",
  138. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  139. ]
  140. STATICFILES_DIRS = [
  141. os.path.join(PROJECT_DIR, "static"),
  142. ]
  143. STATIC_ROOT = os.path.join(PROJECT_DIR, "collect_static")
  144. STATIC_URL = "/static/"
  145. MEDIA_ROOT = os.path.join(PROJECT_DIR, "media")
  146. MEDIA_URL = "/media/"
  147. # Override in local settings or replace with your own key. Please don't use our demo key in production!
  148. GOOGLE_MAP_API_KEY = "AIzaSyD31CT9P9KxvNUJOwDq2kcFEIG8ADgaFgw"
  149. # Use Elasticsearch as the search backend for extra performance and better search results
  150. WAGTAILSEARCH_BACKENDS = {
  151. "default": {
  152. "BACKEND": "wagtail.search.backends.database",
  153. "INDEX": "bakerydemo",
  154. },
  155. }
  156. # Wagtail settings
  157. WAGTAIL_SITE_NAME = "bakerydemo"
  158. WAGTAIL_I18N_ENABLED = True
  159. WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [
  160. ("en", "English"),
  161. ("de", "Deutsch"),
  162. ("ar", "العربيّة"),
  163. ]
  164. ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "changeme")
  165. # Content Security policy settings
  166. # http://django-csp.readthedocs.io/en/latest/configuration.html
  167. # Only enable CSP when enabled through environment variables.
  168. if "CSP_DEFAULT_SRC" in os.environ:
  169. MIDDLEWARE.append("csp.middleware.CSPMiddleware")
  170. # Only report violations, don't enforce policy
  171. CSP_REPORT_ONLY = True
  172. # The “special” source values of 'self', 'unsafe-inline', 'unsafe-eval', and 'none' must be quoted!
  173. # e.g.: CSP_DEFAULT_SRC = "'self'" Without quotes they will not work as intended.
  174. CSP_DEFAULT_SRC = os.environ.get("CSP_DEFAULT_SRC").split(",")
  175. if "CSP_SCRIPT_SRC" in os.environ:
  176. CSP_SCRIPT_SRC = os.environ.get("CSP_SCRIPT_SRC").split(",")
  177. if "CSP_STYLE_SRC" in os.environ:
  178. CSP_STYLE_SRC = os.environ.get("CSP_STYLE_SRC").split(",")
  179. if "CSP_IMG_SRC" in os.environ:
  180. CSP_IMG_SRC = os.environ.get("CSP_IMG_SRC").split(",")
  181. if "CSP_CONNECT_SRC" in os.environ:
  182. CSP_CONNECT_SRC = os.environ.get("CSP_CONNECT_SRC").split(",")
  183. if "CSP_FONT_SRC" in os.environ:
  184. CSP_FONT_SRC = os.environ.get("CSP_FONT_SRC").split(",")
  185. if "CSP_BASE_URI" in os.environ:
  186. CSP_BASE_URI = os.environ.get("CSP_BASE_URI").split(",")
  187. if "CSP_OBJECT_SRC" in os.environ:
  188. CSP_OBJECT_SRC = os.environ.get("CSP_OBJECT_SRC").split(",")