2015-07-28 23:23:46 +03:00
|
|
|
import logging
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2017-01-17 06:38:52 +03:00
|
|
|
from .base import * # noqa
|
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
|
2016-04-13 00:23:00 +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
|
|
|
|
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
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
DATABASES['default'] = env.db('DATABASE_URL')
|
|
|
|
DATABASES['default']['ATOMIC_REQUESTS'] = True
|
|
|
|
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 = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'django_redis.cache.RedisCache',
|
|
|
|
'LOCATION': "{}/0".format(env('REDIS_URL', default='redis://127.0.0.1:6379')),
|
|
|
|
'OPTIONS': {
|
|
|
|
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
|
|
|
# Mimicing memcache behavior.
|
|
|
|
# http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior
|
|
|
|
'IGNORE_EXCEPTIONS': True,
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
|
|
|
|
SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True)
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure
|
2016-06-04 02:07:27 +03:00
|
|
|
SESSION_COOKIE_SECURE = True
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-httponly
|
2015-04-20 00:09:00 +03:00
|
|
|
SESSION_COOKIE_HTTPONLY = True
|
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
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-httponly
|
2016-06-04 02:07:27 +03:00
|
|
|
CSRF_COOKIE_HTTPONLY = True
|
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
|
|
|
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool('DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS', default=True)
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
|
|
|
|
SECURE_HSTS_PRELOAD = env.bool('DJANGO_SECURE_HSTS_PRELOAD', default=True)
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
|
|
|
|
SECURE_CONTENT_TYPE_NOSNIFF = env.bool('DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True)
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-browser-xss-filter
|
|
|
|
SECURE_BROWSER_XSS_FILTER = True
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#x-frame-options
|
2016-06-04 02:07:27 +03:00
|
|
|
X_FRAME_OPTIONS = 'DENY'
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# STORAGES
|
2015-04-20 00:09:00 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://django-storages.readthedocs.io/en/latest/#installation
|
|
|
|
INSTALLED_APPS += ['storages']
|
|
|
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
2015-04-24 15:12:34 +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
|
2015-04-24 15:12:34 +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
|
2015-04-24 15:12:34 +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_AUTO_CREATE_BUCKET = True
|
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 = {
|
2018-03-06 14:28:25 +03:00
|
|
|
'CacheControl': 'max-age=%d, s-maxage=%d, must-revalidate' % (_AWS_EXPIRY, _AWS_EXPIRY),
|
2015-04-20 00:09:00 +03:00
|
|
|
}
|
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# STATIC
|
|
|
|
# ------------------------
|
|
|
|
{% if cookiecutter.use_whitenoise == 'y' -%}
|
|
|
|
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|
|
|
{%- else %}
|
|
|
|
STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage'
|
|
|
|
STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
# MEDIA
|
|
|
|
# ------------------------------------------------------------------------------
|
2016-03-02 17:49:34 +03:00
|
|
|
{% if cookiecutter.use_whitenoise == 'y' -%}
|
2017-08-02 22:10:49 +03:00
|
|
|
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
|
2018-03-06 14:28:25 +03:00
|
|
|
MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
|
|
|
|
{%- else %}
|
|
|
|
# region http://stackoverflow.com/questions/10390244/
|
2017-08-02 22:00:03 +03:00
|
|
|
from storages.backends.s3boto3 import S3Boto3Storage
|
2017-10-12 20:36:44 +03:00
|
|
|
StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static') # noqa
|
2017-12-13 16:06:48 +03:00
|
|
|
MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media', file_overwrite=False) # noqa
|
2018-03-06 14:28:25 +03:00
|
|
|
# endregion
|
2016-03-03 00:02:28 +03:00
|
|
|
DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage'
|
2016-03-02 17:49:34 +03:00
|
|
|
MEDIA_URL = 'https://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME
|
|
|
|
{%- endif %}
|
2015-04-26 12:57:45 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# TEMPLATES
|
2016-06-18 05:07:45 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-06 14:28:25 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
|
|
|
TEMPLATES[0]['OPTIONS']['loaders'] = [
|
|
|
|
(
|
|
|
|
'django.template.loaders.cached.Loader',
|
|
|
|
[
|
|
|
|
'django.template.loaders.filesystem.Loader',
|
|
|
|
'django.template.loaders.app_directories.Loader',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
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(
|
|
|
|
'DJANGO_DEFAULT_FROM_EMAIL',
|
|
|
|
default='{{cookiecutter.project_name}} <noreply@{{cookiecutter.domain_name}}>'
|
|
|
|
)
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#server-email
|
2015-07-16 12:10:36 +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
|
|
|
|
EMAIL_SUBJECT_PREFIX = env('DJANGO_EMAIL_SUBJECT_PREFIX', default='[{{cookiecutter.project_name}}]')
|
|
|
|
|
|
|
|
# ADMIN
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Django Admin URL regex.
|
|
|
|
ADMIN_URL = env('DJANGO_ADMIN_URL')
|
2016-05-27 21:31:30 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# Anymail (Mailgun)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail
|
|
|
|
INSTALLED_APPS += ['anymail']
|
|
|
|
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
|
|
|
|
# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference
|
2016-05-27 21:31:30 +03:00
|
|
|
ANYMAIL = {
|
2018-03-05 20:56:45 +03:00
|
|
|
'MAILGUN_API_KEY': env('MAILGUN_API_KEY'),
|
|
|
|
'MAILGUN_SENDER_DOMAIN': env('MAILGUN_DOMAIN')
|
2016-05-27 21:31:30 +03:00
|
|
|
}
|
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# Gunicorn
|
2015-04-20 00:09:00 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-06 14:28:25 +03:00
|
|
|
INSTALLED_APPS += ['gunicorn']
|
2018-03-04 17:33:54 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
{% if cookiecutter.use_whitenoise == 'y' -%}
|
|
|
|
# WhiteNoise
|
2015-04-20 00:09:00 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-06 14:28:25 +03:00
|
|
|
# http://whitenoise.evans.io/en/latest/django.html#enable-whitenoise
|
|
|
|
MIDDLEWARE = ['whitenoise.middleware.WhiteNoiseMiddleware'] + MIDDLEWARE
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
{%- endif %}
|
|
|
|
{% if cookiecutter.use_compressor == 'y' -%}
|
|
|
|
# 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
|
|
|
|
COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)
|
|
|
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
|
|
|
|
COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
|
|
|
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL
|
|
|
|
COMPRESS_URL = STATIC_URL
|
2018-01-15 23:33:51 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
{%- endif %}
|
|
|
|
{% if cookiecutter.use_whitenoise == 'n' -%}
|
|
|
|
# Collectfast
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://github.com/antonagestam/collectfast#installation
|
|
|
|
INSTALLED_APPS = ['collectfast'] + INSTALLED_APPS
|
|
|
|
AWS_PRELOAD_METADATA = True
|
|
|
|
|
|
|
|
{%- endif %}
|
|
|
|
{% if cookiecutter.use_sentry_for_error_reporting == 'y' -%}
|
|
|
|
# raven
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.sentry.io/clients/python/integrations/django/
|
|
|
|
INSTALLED_APPS += ['raven.contrib.django.raven_compat']
|
|
|
|
MIDDLEWARE = ['raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware'] + MIDDLEWARE
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
# Sentry
|
|
|
|
# ------------------------------------------------------------------------------
|
2015-09-02 23:10:37 +03:00
|
|
|
SENTRY_DSN = env('DJANGO_SENTRY_DSN')
|
|
|
|
SENTRY_CLIENT = env('DJANGO_SENTRY_CLIENT', default='raven.contrib.django.raven_compat.DjangoClient')
|
2015-07-27 18:42:23 +03:00
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
|
|
|
'disable_existing_loggers': True,
|
|
|
|
'root': {
|
|
|
|
'level': 'WARNING',
|
2018-03-06 14:28:25 +03:00
|
|
|
'handlers': ['sentry'],
|
2015-07-27 18:42:23 +03:00
|
|
|
},
|
|
|
|
'formatters': {
|
|
|
|
'verbose': {
|
|
|
|
'format': '%(levelname)s %(asctime)s %(module)s '
|
|
|
|
'%(process)d %(thread)d %(message)s'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'handlers': {
|
|
|
|
'sentry': {
|
|
|
|
'level': 'ERROR',
|
|
|
|
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
|
|
|
|
},
|
|
|
|
'console': {
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
'formatter': 'verbose'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'django.db.backends': {
|
|
|
|
'level': 'ERROR',
|
2018-03-06 14:28:25 +03:00
|
|
|
'handlers': ['console'],
|
2015-07-27 18:42:23 +03:00
|
|
|
'propagate': False,
|
|
|
|
},
|
|
|
|
'raven': {
|
|
|
|
'level': 'DEBUG',
|
2018-03-06 14:28:25 +03:00
|
|
|
'handlers': ['console'],
|
2015-07-27 18:42:23 +03:00
|
|
|
'propagate': False,
|
|
|
|
},
|
|
|
|
'sentry.errors': {
|
|
|
|
'level': 'DEBUG',
|
2018-03-06 14:28:25 +03:00
|
|
|
'handlers': ['console'],
|
2015-07-27 18:42:23 +03:00
|
|
|
'propagate': False,
|
|
|
|
},
|
2015-09-02 23:59:40 +03:00
|
|
|
'django.security.DisallowedHost': {
|
|
|
|
'level': 'ERROR',
|
2018-03-06 14:28:25 +03:00
|
|
|
'handlers': ['console', 'sentry'],
|
2015-09-02 23:59:40 +03:00
|
|
|
'propagate': False,
|
|
|
|
},
|
2015-07-27 18:42:23 +03:00
|
|
|
},
|
|
|
|
}
|
2018-03-06 14:28:25 +03:00
|
|
|
|
2015-09-02 23:10:37 +03:00
|
|
|
SENTRY_CELERY_LOGLEVEL = env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO)
|
2015-07-27 18:42:23 +03:00
|
|
|
RAVEN_CONFIG = {
|
2015-09-02 23:10:37 +03:00
|
|
|
'CELERY_LOGLEVEL': env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO),
|
|
|
|
'DSN': SENTRY_DSN
|
2015-07-27 18:42:23 +03:00
|
|
|
}
|
2018-03-06 14:28:25 +03:00
|
|
|
{%- else %}
|
|
|
|
# LOGGING
|
2015-10-26 01:30:36 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
|
|
|
|
# A sample logging configuration. The only tangible logging
|
|
|
|
# performed by this configuration is to send an email to
|
2018-03-06 14:28:25 +03:00
|
|
|
# the site admins bon every HTTP 500 error when DEBUG=False.
|
2017-02-21 22:55:51 +03:00
|
|
|
# See https://docs.djangoproject.com/en/dev/topics/logging for
|
2015-10-26 01:30:36 +03:00
|
|
|
# more details on how to customize your logging configuration.
|
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
|
|
|
'disable_existing_loggers': False,
|
|
|
|
'filters': {
|
|
|
|
'require_debug_false': {
|
|
|
|
'()': 'django.utils.log.RequireDebugFalse'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'formatters': {
|
|
|
|
'verbose': {
|
|
|
|
'format': '%(levelname)s %(asctime)s %(module)s '
|
|
|
|
'%(process)d %(thread)d %(message)s'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'handlers': {
|
|
|
|
'mail_admins': {
|
|
|
|
'level': 'ERROR',
|
2018-03-06 14:28:25 +03:00
|
|
|
'filters': ['require_debug_false'],
|
2015-10-26 01:30:36 +03:00
|
|
|
'class': 'django.utils.log.AdminEmailHandler'
|
|
|
|
},
|
|
|
|
'console': {
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
'formatter': 'verbose',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'django.request': {
|
2018-03-06 14:28:25 +03:00
|
|
|
'handlers': ['mail_admins'],
|
2015-10-26 01:30:36 +03:00
|
|
|
'level': 'ERROR',
|
|
|
|
'propagate': True
|
|
|
|
},
|
|
|
|
'django.security.DisallowedHost': {
|
|
|
|
'level': 'ERROR',
|
2018-03-06 14:28:25 +03:00
|
|
|
'handlers': ['console', 'mail_admins'],
|
2015-10-26 01:30:36 +03:00
|
|
|
'propagate': True
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-04 00:54:29 +03:00
|
|
|
|
2018-03-06 14:28:25 +03:00
|
|
|
{%- endif %}
|
|
|
|
{% if cookiecutter.use_opbeat == 'y' -%}
|
|
|
|
# opbeat
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://opbeat.com/docs/articles/get-started-with-django/#setup
|
|
|
|
INSTALLED_APPS += ['opbeat.contrib.django']
|
|
|
|
# https://opbeat.com/docs/articles/get-started-with-django/#setup
|
|
|
|
OPBEAT = {
|
|
|
|
'ORGANIZATION_ID': env('DJANGO_OPBEAT_ORGANIZATION_ID'),
|
|
|
|
'APP_ID': env('DJANGO_OPBEAT_APP_ID'),
|
|
|
|
'SECRET_TOKEN': env('DJANGO_OPBEAT_SECRET_TOKEN')
|
|
|
|
}
|
|
|
|
# https://opbeat.com/docs/articles/get-started-with-django/#performance-metrics
|
|
|
|
MIDDLEWARE = ['opbeat.contrib.django.middleware.OpbeatAPMMiddleware'] + MIDDLEWARE
|
|
|
|
|
|
|
|
{%- endif %}
|
|
|
|
# Your stuff...
|
2016-08-31 18:56:25 +03:00
|
|
|
# ------------------------------------------------------------------------------
|