2
0

base.py 6.8 KB

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