2024-02-13 13:57:53 +03:00
|
|
|
# ruff: noqa: E501
|
2018-05-09 13:42:20 +03:00
|
|
|
{% if cookiecutter.use_sentry == 'y' -%}
|
|
|
|
import logging
|
|
|
|
|
2019-03-20 13:04:44 +03:00
|
|
|
import sentry_sdk
|
2023-04-03 16:34:45 +03:00
|
|
|
|
2019-03-20 13:04:44 +03:00
|
|
|
{%- if cookiecutter.use_celery == 'y' %}
|
|
|
|
from sentry_sdk.integrations.celery import CeleryIntegration
|
2023-04-03 16:34:45 +03:00
|
|
|
|
2022-01-08 01:26:56 +03:00
|
|
|
{%- endif %}
|
|
|
|
from sentry_sdk.integrations.django import DjangoIntegration
|
|
|
|
from sentry_sdk.integrations.logging import LoggingIntegration
|
2020-12-31 16:02:53 +03:00
|
|
|
from sentry_sdk.integrations.redis import RedisIntegration
|
2019-03-20 13:04:44 +03:00
|
|
|
|
2018-05-09 13:42:20 +03:00
|
|
|
{% endif -%}
|
2024-02-13 13:57:53 +03:00
|
|
|
from .base import * # noqa: F403
|
|
|
|
from .base import DATABASES
|
|
|
|
from .base import INSTALLED_APPS
|
2024-10-21 23:07:25 +03:00
|
|
|
from .base import REDIS_URL
|
2024-02-13 13:57:53 +03:00
|
|
|
{%- if cookiecutter.use_drf == "y" %}
|
|
|
|
from .base import SPECTACULAR_SETTINGS
|
|
|
|
{%- endif %}
|
2018-03-06 19:56:27 +03:00
|
|
|
from .base import env
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# GENERAL
|
2015-04-25 16:29:33 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
2019-03-18 20:49:43 +03:00
|
|
|
SECRET_KEY = env("DJANGO_SECRET_KEY")
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
|
2019-03-18 20:49:43 +03:00
|
|
|
ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=["{{ cookiecutter.domain_name }}"])
|
2015-04-25 16:29:33 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# DATABASES
|
|
|
|
# ------------------------------------------------------------------------------
|
2024-02-13 13:57:53 +03:00
|
|
|
DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60)
|
2016-06-04 02:07:27 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# CACHES
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
CACHES = {
|
2019-03-18 20:49:43 +03:00
|
|
|
"default": {
|
|
|
|
"BACKEND": "django_redis.cache.RedisCache",
|
2024-10-21 23:07:25 +03:00
|
|
|
"LOCATION": REDIS_URL,
|
2019-03-18 20:49:43 +03:00
|
|
|
"OPTIONS": {
|
|
|
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
2024-10-30 10:13:20 +03:00
|
|
|
# Mimicking memcache behavior.
|
2020-08-29 06:59:29 +03:00
|
|
|
# https://github.com/jazzband/django-redis#memcached-exceptions-behavior
|
2019-03-18 20:49:43 +03:00
|
|
|
"IGNORE_EXCEPTIONS": True,
|
|
|
|
},
|
2024-02-13 13:57:53 +03:00
|
|
|
},
|
2015-11-16 18:55:37 +03:00
|
|
|
}
|
2016-06-04 02:07:27 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# SECURITY
|
2016-06-04 02:07:27 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
|
2019-03-18 20:49:43 +03:00
|
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
|
2019-03-18 20:49:43 +03:00
|
|
|
SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure
|
2016-06-04 02:07:27 +03:00
|
|
|
SESSION_COOKIE_SECURE = True
|
2024-05-28 12:10:33 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-name
|
|
|
|
SESSION_COOKIE_NAME = "__Secure-sessionid"
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure
|
2016-06-04 02:07:27 +03:00
|
|
|
CSRF_COOKIE_SECURE = True
|
2024-05-28 12:10:33 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-name
|
|
|
|
CSRF_COOKIE_NAME = "__Secure-csrftoken"
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/topics/security/#ssl-https
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds
|
|
|
|
# TODO: set this to 60 seconds first and then to 518400 once you prove the former works
|
|
|
|
SECURE_HSTS_SECONDS = 60
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains
|
2024-02-13 13:57:53 +03:00
|
|
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
|
|
|
|
"DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS",
|
|
|
|
default=True,
|
|
|
|
)
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
|
2019-03-18 20:49:43 +03:00
|
|
|
SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True)
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
|
2024-02-13 13:57:53 +03:00
|
|
|
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
|
|
|
|
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF",
|
|
|
|
default=True,
|
|
|
|
)
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2019-04-02 09:13:31 +03:00
|
|
|
{% if cookiecutter.cloud_provider == 'AWS' %}
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
2019-03-18 20:49:43 +03:00
|
|
|
AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID")
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
2019-03-18 20:49:43 +03:00
|
|
|
AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY")
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
2019-03-18 20:49:43 +03:00
|
|
|
AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME")
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
2015-04-20 00:09:00 +03:00
|
|
|
AWS_QUERYSTRING_AUTH = False
|
2018-03-06 14:28:25 +03:00
|
|
|
# DO NOT change these unless you know what you're doing.
|
|
|
|
_AWS_EXPIRY = 60 * 60 * 24 * 7
|
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
2018-02-13 18:04:43 +03:00
|
|
|
AWS_S3_OBJECT_PARAMETERS = {
|
2023-04-15 17:43:04 +03:00
|
|
|
"CacheControl": f"max-age={_AWS_EXPIRY}, s-maxage={_AWS_EXPIRY}, must-revalidate",
|
2015-04-20 00:09:00 +03:00
|
|
|
}
|
2019-04-02 16:43:48 +03:00
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
2022-10-19 22:15:25 +03:00
|
|
|
AWS_S3_MAX_MEMORY_SIZE = env.int(
|
|
|
|
"DJANGO_AWS_S3_MAX_MEMORY_SIZE",
|
|
|
|
default=100_000_000, # 100MB
|
|
|
|
)
|
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
2019-04-02 16:43:48 +03:00
|
|
|
AWS_S3_REGION_NAME = env("DJANGO_AWS_S3_REGION_NAME", default=None)
|
2020-05-17 18:37:35 +03:00
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#cloudfront
|
|
|
|
AWS_S3_CUSTOM_DOMAIN = env("DJANGO_AWS_S3_CUSTOM_DOMAIN", default=None)
|
|
|
|
aws_s3_domain = AWS_S3_CUSTOM_DOMAIN or f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com"
|
2019-05-19 02:24:29 +03:00
|
|
|
{% elif cookiecutter.cloud_provider == 'GCP' %}
|
|
|
|
GS_BUCKET_NAME = env("DJANGO_GCP_STORAGE_BUCKET_NAME")
|
2019-04-06 22:04:22 +03:00
|
|
|
GS_DEFAULT_ACL = "publicRead"
|
2022-11-30 21:26:58 +03:00
|
|
|
{% elif cookiecutter.cloud_provider == 'Azure' %}
|
|
|
|
AZURE_ACCOUNT_KEY = env("DJANGO_AZURE_ACCOUNT_KEY")
|
|
|
|
AZURE_ACCOUNT_NAME = env("DJANGO_AZURE_ACCOUNT_NAME")
|
|
|
|
AZURE_CONTAINER = env("DJANGO_AZURE_CONTAINER_NAME")
|
2019-05-27 18:33:07 +03:00
|
|
|
{% endif -%}
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2019-05-27 18:33:07 +03:00
|
|
|
{% if cookiecutter.cloud_provider != 'None' or cookiecutter.use_whitenoise == 'y' -%}
|
2024-01-24 18:32:44 +03:00
|
|
|
# STATIC & MEDIA
|
2018-03-06 14:28:25 +03:00
|
|
|
# ------------------------
|
2024-01-24 18:32:44 +03:00
|
|
|
STORAGES = {
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'y' and cookiecutter.cloud_provider == 'None' %}
|
2024-01-24 18:32:44 +03:00
|
|
|
"default": {
|
|
|
|
"BACKEND": "django.core.files.storage.FileSystemStorage",
|
|
|
|
},
|
|
|
|
"staticfiles": {
|
|
|
|
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
|
|
|
},
|
|
|
|
{%- elif cookiecutter.cloud_provider == 'AWS' %}
|
|
|
|
"default": {
|
2024-01-25 12:01:27 +03:00
|
|
|
"BACKEND": "storages.backends.s3.S3Storage",
|
|
|
|
"OPTIONS": {
|
|
|
|
"location": "media",
|
|
|
|
"file_overwrite": False,
|
|
|
|
},
|
2024-01-24 18:32:44 +03:00
|
|
|
},
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'y' %}
|
|
|
|
"staticfiles": {
|
|
|
|
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
|
|
|
},
|
|
|
|
{%- else %}
|
2024-01-24 18:32:44 +03:00
|
|
|
"staticfiles": {
|
2024-01-25 12:01:27 +03:00
|
|
|
"BACKEND": "storages.backends.s3.S3Storage",
|
|
|
|
"OPTIONS": {
|
|
|
|
"location": "static",
|
|
|
|
"default_acl": "public-read",
|
|
|
|
},
|
2024-01-24 18:32:44 +03:00
|
|
|
},
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- endif %}
|
2024-01-24 18:32:44 +03:00
|
|
|
{%- elif cookiecutter.cloud_provider == 'GCP' %}
|
|
|
|
"default": {
|
2024-01-25 12:01:27 +03:00
|
|
|
"BACKEND": "storages.backends.gcloud.GoogleCloudStorage",
|
|
|
|
"OPTIONS": {
|
|
|
|
"location": "media",
|
|
|
|
"file_overwrite": False,
|
|
|
|
},
|
2024-01-24 18:32:44 +03:00
|
|
|
},
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'y' %}
|
|
|
|
"staticfiles": {
|
|
|
|
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
|
|
|
},
|
|
|
|
{%- else %}
|
2024-01-24 18:32:44 +03:00
|
|
|
"staticfiles": {
|
2024-01-25 12:01:27 +03:00
|
|
|
"BACKEND": "storages.backends.gcloud.GoogleCloudStorage",
|
|
|
|
"OPTIONS": {
|
|
|
|
"location": "static",
|
|
|
|
"default_acl": "publicRead",
|
|
|
|
},
|
2024-01-24 18:32:44 +03:00
|
|
|
},
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- endif %}
|
2024-01-24 18:32:44 +03:00
|
|
|
{%- elif cookiecutter.cloud_provider == 'Azure' %}
|
|
|
|
"default": {
|
2024-01-25 12:01:27 +03:00
|
|
|
"BACKEND": "storages.backends.azure_storage.AzureStorage",
|
|
|
|
"OPTIONS": {
|
|
|
|
"location": "media",
|
2024-10-21 12:12:29 +03:00
|
|
|
"overwrite_files": False,
|
2024-01-25 12:01:27 +03:00
|
|
|
},
|
2024-01-24 18:32:44 +03:00
|
|
|
},
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'y' %}
|
|
|
|
"staticfiles": {
|
|
|
|
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
|
|
|
},
|
|
|
|
{%- else %}
|
2024-01-24 18:32:44 +03:00
|
|
|
"staticfiles": {
|
2024-01-25 12:01:27 +03:00
|
|
|
"BACKEND": "storages.backends.azure_storage.AzureStorage",
|
|
|
|
"OPTIONS": {
|
|
|
|
"location": "static",
|
|
|
|
},
|
2024-01-24 18:32:44 +03:00
|
|
|
},
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- endif %}
|
2024-01-24 18:32:44 +03:00
|
|
|
{%- endif %}
|
|
|
|
}
|
|
|
|
{%- endif %}
|
2018-03-06 14:28:25 +03:00
|
|
|
|
2019-04-02 09:13:31 +03:00
|
|
|
{%- if cookiecutter.cloud_provider == 'AWS' %}
|
2020-05-17 18:37:35 +03:00
|
|
|
MEDIA_URL = f"https://{aws_s3_domain}/media/"
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'n' %}
|
2024-07-09 11:11:15 +03:00
|
|
|
COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3Strategy"
|
2024-01-24 18:32:44 +03:00
|
|
|
STATIC_URL = f"https://{aws_s3_domain}/static/"
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- endif %}
|
2019-05-19 02:24:29 +03:00
|
|
|
{%- elif cookiecutter.cloud_provider == 'GCP' %}
|
2019-05-27 17:58:56 +03:00
|
|
|
MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/"
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'n' %}
|
2024-07-09 11:11:15 +03:00
|
|
|
COLLECTFASTA_STRATEGY = "collectfasta.strategies.gcloud.GoogleCloudStrategy"
|
2024-01-24 18:32:44 +03:00
|
|
|
STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/"
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- endif %}
|
2022-11-30 21:26:58 +03:00
|
|
|
{%- elif cookiecutter.cloud_provider == 'Azure' %}
|
|
|
|
MEDIA_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/media/"
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'n' %}
|
2024-01-24 18:32:44 +03:00
|
|
|
STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/"
|
2016-03-02 17:49:34 +03:00
|
|
|
{%- endif %}
|
2024-05-13 23:45:55 +03:00
|
|
|
{%- endif %}
|
2015-04-26 12:57:45 +03:00
|
|
|
|
2015-04-20 00:09:00 +03:00
|
|
|
# EMAIL
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email
|
|
|
|
DEFAULT_FROM_EMAIL = env(
|
2022-01-08 01:26:56 +03:00
|
|
|
"DJANGO_DEFAULT_FROM_EMAIL",
|
|
|
|
default="{{cookiecutter.project_name}} <noreply@{{cookiecutter.domain_name}}>",
|
2018-03-06 14:28:25 +03:00
|
|
|
)
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#server-email
|
2019-03-18 20:49:43 +03:00
|
|
|
SERVER_EMAIL = env("DJANGO_SERVER_EMAIL", default=DEFAULT_FROM_EMAIL)
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
|
2019-03-18 20:49:43 +03:00
|
|
|
EMAIL_SUBJECT_PREFIX = env(
|
2021-03-03 01:50:28 +03:00
|
|
|
"DJANGO_EMAIL_SUBJECT_PREFIX",
|
2023-07-10 19:20:36 +03:00
|
|
|
default="[{{cookiecutter.project_name}}] ",
|
2019-03-18 20:49:43 +03:00
|
|
|
)
|
2024-09-18 00:35:57 +03:00
|
|
|
ACCOUNT_EMAIL_SUBJECT_PREFIX = EMAIL_SUBJECT_PREFIX
|
2018-03-06 14:28:25 +03:00
|
|
|
|
|
|
|
# ADMIN
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Django Admin URL regex.
|
2019-03-18 20:49:43 +03:00
|
|
|
ADMIN_URL = env("DJANGO_ADMIN_URL")
|
2016-05-27 21:31:30 +03:00
|
|
|
|
2020-02-07 00:58:15 +03:00
|
|
|
# Anymail
|
2018-03-06 14:28:25 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail
|
2024-02-13 13:57:53 +03:00
|
|
|
INSTALLED_APPS += ["anymail"]
|
2020-03-14 20:43:37 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference
|
2020-03-14 20:43:37 +03:00
|
|
|
{%- if cookiecutter.mail_service == 'Mailgun' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps/mailgun/
|
|
|
|
EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
|
2016-05-27 21:31:30 +03:00
|
|
|
ANYMAIL = {
|
2019-03-18 20:49:43 +03:00
|
|
|
"MAILGUN_API_KEY": env("MAILGUN_API_KEY"),
|
|
|
|
"MAILGUN_SENDER_DOMAIN": env("MAILGUN_DOMAIN"),
|
2019-04-02 16:08:51 +03:00
|
|
|
"MAILGUN_API_URL": env("MAILGUN_API_URL", default="https://api.mailgun.net/v3"),
|
2016-05-27 21:31:30 +03:00
|
|
|
}
|
2020-03-14 20:43:37 +03:00
|
|
|
{%- elif cookiecutter.mail_service == 'Amazon SES' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps/amazon_ses/
|
|
|
|
EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend"
|
|
|
|
ANYMAIL = {}
|
|
|
|
{%- elif cookiecutter.mail_service == 'Mailjet' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps/mailjet/
|
|
|
|
EMAIL_BACKEND = "anymail.backends.mailjet.EmailBackend"
|
|
|
|
ANYMAIL = {
|
2020-02-07 00:58:15 +03:00
|
|
|
"MAILJET_API_KEY": env("MAILJET_API_KEY"),
|
|
|
|
"MAILJET_SECRET_KEY": env("MAILJET_SECRET_KEY"),
|
2020-03-14 20:43:37 +03:00
|
|
|
}
|
|
|
|
{%- elif cookiecutter.mail_service == 'Mandrill' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps/mandrill/
|
|
|
|
EMAIL_BACKEND = "anymail.backends.mandrill.EmailBackend"
|
|
|
|
ANYMAIL = {
|
2020-02-07 00:58:15 +03:00
|
|
|
"MANDRILL_API_KEY": env("MANDRILL_API_KEY"),
|
2023-04-15 17:43:04 +03:00
|
|
|
"MANDRILL_API_URL": env("MANDRILL_API_URL", default="https://mandrillapp.com/api/1.0"),
|
2020-03-14 20:43:37 +03:00
|
|
|
}
|
|
|
|
{%- elif cookiecutter.mail_service == 'Postmark' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps/postmark/
|
|
|
|
EMAIL_BACKEND = "anymail.backends.postmark.EmailBackend"
|
|
|
|
ANYMAIL = {
|
2020-02-07 00:58:15 +03:00
|
|
|
"POSTMARK_SERVER_TOKEN": env("POSTMARK_SERVER_TOKEN"),
|
2020-03-14 22:09:05 +03:00
|
|
|
"POSTMARK_API_URL": env("POSTMARK_API_URL", default="https://api.postmarkapp.com/"),
|
2020-03-14 20:43:37 +03:00
|
|
|
}
|
|
|
|
{%- elif cookiecutter.mail_service == 'Sendgrid' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps/sendgrid/
|
|
|
|
EMAIL_BACKEND = "anymail.backends.sendgrid.EmailBackend"
|
|
|
|
ANYMAIL = {
|
2020-02-07 00:58:15 +03:00
|
|
|
"SENDGRID_API_KEY": env("SENDGRID_API_KEY"),
|
2020-03-14 22:09:05 +03:00
|
|
|
"SENDGRID_API_URL": env("SENDGRID_API_URL", default="https://api.sendgrid.com/v3/"),
|
2020-03-14 20:43:37 +03:00
|
|
|
}
|
2024-05-27 16:46:12 +03:00
|
|
|
{%- elif cookiecutter.mail_service == 'Brevo' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps/brevo/
|
|
|
|
EMAIL_BACKEND = "anymail.backends.brevo.EmailBackend"
|
2020-03-14 20:43:37 +03:00
|
|
|
ANYMAIL = {
|
2024-05-27 16:46:12 +03:00
|
|
|
"BREVO_API_KEY": env("BREVO_API_KEY"),
|
|
|
|
"BREVO_API_URL": env("BREVO_API_URL", default="https://api.brevo.com/v3/"),
|
2020-03-14 20:43:37 +03:00
|
|
|
}
|
|
|
|
{%- elif cookiecutter.mail_service == 'SparkPost' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps/sparkpost/
|
|
|
|
EMAIL_BACKEND = "anymail.backends.sparkpost.EmailBackend"
|
|
|
|
ANYMAIL = {
|
2020-02-07 00:58:15 +03:00
|
|
|
"SPARKPOST_API_KEY": env("SPARKPOST_API_KEY"),
|
2023-04-15 17:43:04 +03:00
|
|
|
"SPARKPOST_API_URL": env("SPARKPOST_API_URL", default="https://api.sparkpost.com/api/v1"),
|
2016-05-27 21:31:30 +03:00
|
|
|
}
|
2020-03-14 20:43:37 +03:00
|
|
|
{%- elif cookiecutter.mail_service == 'Other SMTP' %}
|
|
|
|
# https://anymail.readthedocs.io/en/stable/esps
|
|
|
|
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
|
|
|
ANYMAIL = {}
|
|
|
|
{%- endif %}
|
2016-05-27 21:31:30 +03:00
|
|
|
|
2022-03-20 18:00:40 +03:00
|
|
|
{% if cookiecutter.frontend_pipeline == 'Django Compressor' -%}
|
2018-03-06 14:28:25 +03:00
|
|
|
# django-compressor
|
2015-04-20 00:09:00 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
|
2019-03-18 20:49:43 +03:00
|
|
|
COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True)
|
2020-08-14 01:45:37 +03:00
|
|
|
{%- if cookiecutter.cloud_provider == 'None' %}
|
2020-08-14 10:12:55 +03:00
|
|
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
|
2020-08-14 01:45:37 +03:00
|
|
|
COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage"
|
2022-11-30 21:26:58 +03:00
|
|
|
{%- elif cookiecutter.cloud_provider in ('AWS', 'GCP', 'Azure') and cookiecutter.use_whitenoise == 'n' %}
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
|
2024-01-24 18:32:44 +03:00
|
|
|
COMPRESS_STORAGE = STORAGES["staticfiles"]["BACKEND"]
|
2020-02-11 23:17:50 +03:00
|
|
|
{%- endif %}
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL
|
2024-05-14 00:26:26 +03:00
|
|
|
COMPRESS_URL = STATIC_URL{% if cookiecutter.use_whitenoise == 'y' or cookiecutter.cloud_provider == 'None' %} # noqa: F405
|
|
|
|
{%- endif -%}
|
2020-02-11 23:17:50 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'y' %}
|
|
|
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
|
|
|
|
COMPRESS_OFFLINE = True # Offline compression is required when using Whitenoise
|
|
|
|
{%- endif %}
|
|
|
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_FILTERS
|
|
|
|
COMPRESS_FILTERS = {
|
|
|
|
"css": [
|
|
|
|
"compressor.filters.css_default.CssAbsoluteFilter",
|
|
|
|
"compressor.filters.cssmin.rCSSMinFilter",
|
|
|
|
],
|
|
|
|
"js": ["compressor.filters.jsmin.JSMinFilter"],
|
|
|
|
}
|
2018-05-21 21:57:52 +03:00
|
|
|
{% endif %}
|
2024-10-21 12:12:29 +03:00
|
|
|
{%- if cookiecutter.use_whitenoise == 'n' and cookiecutter.cloud_provider in ('AWS', 'GCP') -%}
|
2024-07-09 11:11:15 +03:00
|
|
|
# Collectfasta
|
2018-03-06 14:28:25 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2024-07-09 11:11:15 +03:00
|
|
|
# https://github.com/jasongi/collectfasta#installation
|
|
|
|
INSTALLED_APPS = ["collectfasta", *INSTALLED_APPS]
|
2018-05-21 21:57:52 +03:00
|
|
|
{% endif %}
|
2019-03-20 13:04:44 +03:00
|
|
|
# LOGGING
|
2018-03-06 14:28:25 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2019-03-20 13:04:44 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#logging
|
|
|
|
# See https://docs.djangoproject.com/en/dev/topics/logging for
|
|
|
|
# more details on how to customize your logging configuration.
|
|
|
|
{% if cookiecutter.use_sentry == 'n' -%}
|
|
|
|
# A sample logging configuration. The only tangible logging
|
|
|
|
# performed by this configuration is to send an email to
|
|
|
|
# the site admins on every HTTP 500 error when DEBUG=False.
|
2015-07-27 18:42:23 +03:00
|
|
|
LOGGING = {
|
2019-03-18 20:49:43 +03:00
|
|
|
"version": 1,
|
2019-03-20 13:04:44 +03:00
|
|
|
"disable_existing_loggers": False,
|
|
|
|
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
|
2019-03-18 20:49:43 +03:00
|
|
|
"formatters": {
|
|
|
|
"verbose": {
|
2023-04-15 17:43:04 +03:00
|
|
|
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
|
|
|
|
},
|
2015-07-27 18:42:23 +03:00
|
|
|
},
|
2019-03-18 20:49:43 +03:00
|
|
|
"handlers": {
|
2019-03-20 13:04:44 +03:00
|
|
|
"mail_admins": {
|
2019-03-18 20:49:43 +03:00
|
|
|
"level": "ERROR",
|
2019-03-20 13:04:44 +03:00
|
|
|
"filters": ["require_debug_false"],
|
|
|
|
"class": "django.utils.log.AdminEmailHandler",
|
2019-03-18 20:49:43 +03:00
|
|
|
},
|
|
|
|
"console": {
|
|
|
|
"level": "DEBUG",
|
|
|
|
"class": "logging.StreamHandler",
|
|
|
|
"formatter": "verbose",
|
2015-07-27 18:42:23 +03:00
|
|
|
},
|
|
|
|
},
|
2019-04-12 18:59:34 +03:00
|
|
|
"root": {"level": "INFO", "handlers": ["console"]},
|
2019-03-18 20:49:43 +03:00
|
|
|
"loggers": {
|
2019-03-20 13:04:44 +03:00
|
|
|
"django.request": {
|
|
|
|
"handlers": ["mail_admins"],
|
2019-03-18 20:49:43 +03:00
|
|
|
"level": "ERROR",
|
2019-03-20 13:04:44 +03:00
|
|
|
"propagate": True,
|
2015-07-27 18:42:23 +03:00
|
|
|
},
|
2019-03-18 20:49:43 +03:00
|
|
|
"django.security.DisallowedHost": {
|
|
|
|
"level": "ERROR",
|
2019-03-20 13:04:44 +03:00
|
|
|
"handlers": ["console", "mail_admins"],
|
|
|
|
"propagate": True,
|
2015-09-02 23:59:40 +03:00
|
|
|
},
|
2015-07-27 18:42:23 +03:00
|
|
|
},
|
|
|
|
}
|
2019-03-20 13:04:44 +03:00
|
|
|
{% else %}
|
2015-10-26 01:30:36 +03:00
|
|
|
LOGGING = {
|
2019-03-18 20:49:43 +03:00
|
|
|
"version": 1,
|
2019-03-20 13:04:44 +03:00
|
|
|
"disable_existing_loggers": True,
|
2019-03-18 20:49:43 +03:00
|
|
|
"formatters": {
|
|
|
|
"verbose": {
|
2023-04-15 17:43:04 +03:00
|
|
|
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
|
|
|
|
},
|
2015-10-26 01:30:36 +03:00
|
|
|
},
|
2019-03-18 20:49:43 +03:00
|
|
|
"handlers": {
|
|
|
|
"console": {
|
|
|
|
"level": "DEBUG",
|
|
|
|
"class": "logging.StreamHandler",
|
|
|
|
"formatter": "verbose",
|
2024-02-13 13:57:53 +03:00
|
|
|
},
|
2015-10-26 01:30:36 +03:00
|
|
|
},
|
2019-04-12 18:59:34 +03:00
|
|
|
"root": {"level": "INFO", "handlers": ["console"]},
|
2019-03-18 20:49:43 +03:00
|
|
|
"loggers": {
|
2019-03-20 13:04:44 +03:00
|
|
|
"django.db.backends": {
|
2019-03-18 20:49:43 +03:00
|
|
|
"level": "ERROR",
|
2019-03-20 13:04:44 +03:00
|
|
|
"handlers": ["console"],
|
|
|
|
"propagate": False,
|
2015-10-26 01:30:36 +03:00
|
|
|
},
|
2019-03-20 13:04:44 +03:00
|
|
|
# Errors logged by the SDK itself
|
|
|
|
"sentry_sdk": {"level": "ERROR", "handlers": ["console"], "propagate": False},
|
2019-03-18 20:49:43 +03:00
|
|
|
"django.security.DisallowedHost": {
|
|
|
|
"level": "ERROR",
|
2019-03-20 13:04:44 +03:00
|
|
|
"handlers": ["console"],
|
|
|
|
"propagate": False,
|
2015-10-26 01:30:36 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-10-04 00:54:29 +03:00
|
|
|
|
2019-03-20 13:04:44 +03:00
|
|
|
# Sentry
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
SENTRY_DSN = env("SENTRY_DSN")
|
|
|
|
SENTRY_LOG_LEVEL = env.int("DJANGO_SENTRY_LOG_LEVEL", logging.INFO)
|
|
|
|
|
|
|
|
sentry_logging = LoggingIntegration(
|
|
|
|
level=SENTRY_LOG_LEVEL, # Capture info and above as breadcrumbs
|
2019-05-22 09:46:20 +03:00
|
|
|
event_level=logging.ERROR, # Send errors as events
|
2019-03-20 13:04:44 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
{%- if cookiecutter.use_celery == 'y' %}
|
2021-04-30 19:50:35 +03:00
|
|
|
integrations = [
|
|
|
|
sentry_logging,
|
|
|
|
DjangoIntegration(),
|
|
|
|
CeleryIntegration(),
|
|
|
|
RedisIntegration(),
|
|
|
|
]
|
2020-08-28 11:17:34 +03:00
|
|
|
{% else %}
|
2020-12-31 16:02:53 +03:00
|
|
|
integrations = [sentry_logging, DjangoIntegration(), RedisIntegration()]
|
2020-08-28 11:17:34 +03:00
|
|
|
{% endif -%}
|
|
|
|
|
2019-03-20 13:04:44 +03:00
|
|
|
sentry_sdk.init(
|
|
|
|
dsn=SENTRY_DSN,
|
2020-08-28 11:17:34 +03:00
|
|
|
integrations=integrations,
|
|
|
|
environment=env("SENTRY_ENVIRONMENT", default="production"),
|
|
|
|
traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE", default=0.0),
|
2019-03-20 13:04:44 +03:00
|
|
|
)
|
2018-05-21 21:57:52 +03:00
|
|
|
{% endif %}
|
2022-12-06 22:26:24 +03:00
|
|
|
{% if cookiecutter.use_drf == "y" -%}
|
|
|
|
|
|
|
|
# django-rest-framework
|
|
|
|
# -------------------------------------------------------------------------------
|
|
|
|
# Tools that generate code samples can use SERVERS to point to the correct domain
|
2024-02-13 13:57:53 +03:00
|
|
|
SPECTACULAR_SETTINGS["SERVERS"] = [
|
2023-04-15 17:43:04 +03:00
|
|
|
{"url": "https://{{ cookiecutter.domain_name }}", "description": "Production server"},
|
2022-12-06 22:26:24 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
{%- endif %}
|
2018-03-06 14:28:25 +03:00
|
|
|
# Your stuff...
|
2016-08-31 18:56:25 +03:00
|
|
|
# ------------------------------------------------------------------------------
|