text: """
  Django settings for dft project.
  """
  import os
  import sys
  
  import dj_database_url
  
  env = os.environ.copy()
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  
  PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  BASE_DIR = os.path.dirname(PROJECT_DIR)
  
  
  # Switch off DEBUG mode explicitly in the base settings.
  # https://docs.djangoproject.com/en/stable/ref/settings/#debug
  DEBUG = False
  
  
  # Secret key is important to be kept secret. Never share it with anyone. Please
  # always set it in the environment variable and never check into the
  # repository.
  # In its default template Django generates a 50-characters long string using
  # the following function:
  # https://github.com/django/django/blob/fd8a7a5313f5e223212085b2e470e43c0047e066/django/core/management/utils.py#L76-L81
  # https://docs.djangoproject.com/en/stable/ref/settings/#allowed-hosts
  if "SECRET_KEY" in env:
      SECRET_KEY = env["SECRET_KEY"]
  
  
  # Define what hosts an app can be accessed by.
  # It will return HTTP 400 Bad Request error if your host is not set using this
  # setting.
  # https://docs.djangoproject.com/en/stable/ref/settings/#allowed-hosts
  if "ALLOWED_HOSTS" in env:
      ALLOWED_HOSTS = env["ALLOWED_HOSTS"].split(",")
  
  
  # Application definition
  
  INSTALLED_APPS = [
      # This is an app that we use for the performance monitoring.
      # You set configure it by setting the following environment variables:
      #  * SCOUT_MONITOR="True"
      #  * SCOUT_KEY="paste api key here"
      #  * SCOUT_NAME="dft"
      # https://intranet.torchbox.com/delivering-projects/tech/scoutapp/
      # According to the official docs, it's important that Scout is listed
      # first - http://help.apm.scoutapp.com/#django.
      "dft.utils",
      "django.contrib.admin",
      "django.contrib.auth",
      "django.contrib.contenttypes",
      "django.contrib.sessions",
      "django.contrib.messages",
      "django.contrib.staticfiles",
      "django.contrib.sitemaps",
      "pattern_library",
      "dft.project_styleguide.apps.ProjectStyleguideConfig",
  ]
  
  
  # Middleware classes
  # https://docs.djangoproject.com/en/stable/ref/settings/#middleware
  # https://docs.djangoproject.com/en/stable/topics/http/middleware/
  MIDDLEWARE = [
      "django.middleware.security.SecurityMiddleware",
      # Whitenoise middleware is used to server static files (CSS, JS, etc.).
      # According to the official documentation it should be listed underneath
      # SecurityMiddleware.
      # http://whitenoise.evans.io/en/stable/#quickstart-for-django-apps
      "whitenoise.middleware.WhiteNoiseMiddleware",
      "django.contrib.sessions.middleware.SessionMiddleware",
      "django.middleware.common.CommonMiddleware",
      "django.middleware.csrf.CsrfViewMiddleware",
      "django.contrib.auth.middleware.AuthenticationMiddleware",
      "django.contrib.messages.middleware.MessageMiddleware",
      "django.middleware.clickjacking.XFrameOptionsMiddleware",
  ]
  
  ROOT_URLCONF = "dft.urls"
  
  TEMPLATES = [
      {
          "BACKEND": "django.template.backends.django.DjangoTemplates",
          "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",
              ],
              "builtins": ["pattern_library.loader_tags"],
          },
      }
  ]
  
  WSGI_APPLICATION = "dft.wsgi.application"
  
  
  # Database
  # This setting will use DATABASE_URL environment variable.
  # https://docs.djangoproject.com/en/stable/ref/settings/#databases
  # https://github.com/kennethreitz/dj-database-url
  
  DATABASES = {
      "default": dj_database_url.config(
          conn_max_age=600, default="postgres:///dft"
      )
  }
  
  
  # Server-side cache settings. Do not confuse with front-end cache.
  # https://docs.djangoproject.com/en/stable/topics/cache/
  CACHES = {
      "default": {
          "BACKEND": "django.core.cache.backends.db.DatabaseCache",
          "LOCATION": "database_cache",
      }
  }
  
  # Password validation
  # https://docs.djangoproject.com/en/stable/ref/settings/#auth-password-validators
  
  AUTH_PASSWORD_VALIDATORS = [
      {
          "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
      },
      {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
      {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
      {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
  ]
  
  
  # Internationalization
  # https://docs.djangoproject.com/en/stable/topics/i18n/
  
  LANGUAGE_CODE = "en-gb"
  
  TIME_ZONE = "Europe/London"
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/stable/howto/static-files/
  
  # We serve static files with Whitenoise (set in MIDDLEWARE). It also comes with
  # a custom backend for the static files storage. It makes files cacheable
  # (cache-control headers) for a long time and adds hashes to the file names,
  # e.g. main.css -> main.1jasdiu12.css.
  # The static files with this backend are generated when you run
  # "django-admin collectstatic".
  # http://whitenoise.evans.io/en/stable/#quickstart-for-django-apps
  # https://docs.djangoproject.com/en/stable/ref/settings/#staticfiles-storage
  STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
  
  # Place static files that need a specific URL (such as robots.txt and favicon.ico) in the "public" folder
  WHITENOISE_ROOT = os.path.join(BASE_DIR, "public")
  
  
  # This is where Django will look for static files outside the directories of
  # applications which are used by default.
  # https://docs.djangoproject.com/en/stable/ref/settings/#staticfiles-dirs
  STATICFILES_DIRS = [
      # "static_compiled" is a folder used by the front-end tooling
      # to output compiled static assets.
      os.path.join(PROJECT_DIR, "static_compiled")
  ]
  
  
  # This is where Django will put files collected from application directories
  # and custom direcotires set in "STATICFILES_DIRS" when
  # using "django-admin collectstatic" command.
  # https://docs.djangoproject.com/en/stable/ref/settings/#static-root
  STATIC_ROOT = env.get("STATIC_DIR", os.path.join(BASE_DIR, "static"))
  
  
  # This is the URL that will be used when serving static files, e.g.
  # https://llamasavers.com/static/
  # https://docs.djangoproject.com/en/stable/ref/settings/#static-url
  STATIC_URL = env.get("STATIC_URL", "/assets/")
  
  
  # Where in the filesystem the media (user uploaded) content is stored.
  # MEDIA_ROOT is not used when S3 backend is set up.
  # Probably only relevant to the local development.
  # https://docs.djangoproject.com/en/stable/ref/settings/#media-root
  MEDIA_ROOT = env.get("MEDIA_DIR", os.path.join(BASE_DIR, "media"))
  
  
  # The URL path that media files will be accessible at. This setting won't be
  # used if S3 backend is set up.
  # Probably only relevant to the local development.
  # https://docs.djangoproject.com/en/stable/ref/settings/#media-url
  MEDIA_URL = env.get("MEDIA_URL", "/media/")
  
  
  # Logging
  # This logging is configured to be used with Sentry and console logs. Console
  # logs are widely used by platforms offering Docker deployments, e.g. Heroku.
  # We use Sentry to only send error logs so we're notified about errors that are
  # not Python exceptions.
  # We do not use default mail or file handlers because they are of no use for
  # us.
  # https://docs.djangoproject.com/en/stable/topics/logging/
  LOGGING = {
      "version": 1,
      "disable_existing_loggers": False,
      "handlers": {
          # Send logs with at least INFO level to the console.
          "console": {
              "level": "INFO",
              "class": "logging.StreamHandler",
              "formatter": "verbose",
          },
      },
      "formatters": {
          "verbose": {
              "format": "[%(asctime)s][%(process)d][%(levelname)s][%(name)s] %(message)s"
          }
      },
      "loggers": {
          "dft": {
              "handlers": ["console"],
              "level": "INFO",
              "propagate": False,
          },
          "django.request": {
              "handlers": ["console"],
              "level": "WARNING",
              "propagate": False,
          },
          "django.security": {
              "handlers": ["console"],
              "level": "WARNING",
              "propagate": False,
          },
      },
  }
  
  
  # Security configuration
  # This configuration is required to achieve good security rating.
  # You can test it using https://securityheaders.com/
  # https://docs.djangoproject.com/en/stable/ref/middleware/#module-django.middleware.security
  
  # When set to True, client-side JavaScript will not to be able to access the CSRF cookie.
  # https://docs.djangoproject.com/en/stable/ref/settings/#csrf-cookie-httponly
  CSRF_COOKIE_HTTPONLY = True
  
  # Force HTTPS redirect
  # https://docs.djangoproject.com/en/stable/ref/settings/#secure-ssl-redirect
  if env.get("SECURE_SSL_REDIRECT", "true").strip().lower() == "true":
      SECURE_SSL_REDIRECT = True
  
  
  # This will allow the cache to swallow the fact that the website is behind TLS
  # and inform the Django using "X-Forwarded-Proto" HTTP header.
  # https://docs.djangoproject.com/en/stable/ref/settings/#secure-proxy-ssl-header
  SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
  
  
  # This is a setting setting HSTS header. This will enforce the visitors to use
  # HTTPS for an amount of time specified in the header. Please make sure you
  # consult with sysadmin before setting this.
  # https://docs.djangoproject.com/en/stable/ref/settings/#secure-hsts-seconds
  if "SECURE_HSTS_SECONDS" in env:
      SECURE_HSTS_SECONDS = int(env["SECURE_HSTS_SECONDS"])
  
  
  # https://docs.djangoproject.com/en/stable/ref/settings/#secure-browser-xss-filter
  if env.get("SECURE_BROWSER_XSS_FILTER", "true").lower().strip() == "true":
      SECURE_BROWSER_XSS_FILTER = True
  
  
  # https://docs.djangoproject.com/en/stable/ref/settings/#secure-content-type-nosniff
  if env.get("SECURE_CONTENT_TYPE_NOSNIFF", "true").lower().strip() == "true":
      SECURE_CONTENT_TYPE_NOSNIFF = True
  
  
  # Referrer-policy header settings.
  # https://django-referrer-policy.readthedocs.io/en/1.0/
  
  REFERRER_POLICY = env.get(
      "SECURE_REFERRER_POLICY", "no-referrer-when-downgrade"
  ).strip()
  
  
  # Styleguide
  PATTERN_LIBRARY_ENABLED = env.get("PATTERN_LIBRARY_ENABLED", "false").lower() == "true"
  PATTERN_LIBRARY_TEMPLATE_DIR = os.path.join(
      PROJECT_DIR, "project_styleguide", "templates"
  )
  
  if "NOTIFY_API_TEST_KEY_SEND" in env:
      NOTIFY_API_TEST_KEY_SEND = env.get("NOTIFY_API_TEST_KEY_SEND")
  if "NOTIFY_EMAIL_TEMPLATE_ID" in env:
      NOTIFY_EMAIL_TEMPLATE_ID = env.get("NOTIFY_EMAIL_TEMPLATE_ID")
  if "NOTIFY_EMAIL_ADDRESS" in env:
      NOTIFY_EMAIL_ADDRESS = env.get("NOTIFY_EMAIL_ADDRESS")
  if "NOTIFY_DEMO_PIN" in env:
      NOTIFY_DEMO_PIN = env.get("NOTIFY_DEMO_PIN")
  