2014-05-25 18:50:13 +04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
Production Configurations
|
|
|
|
|
|
|
|
- Use djangosecure
|
|
|
|
- Use Amazon's S3 for storing static files and uploaded media
|
2015-07-07 22:06:46 +03:00
|
|
|
- Use mailgun to send emails
|
2015-07-27 18:42:23 +03:00
|
|
|
- Use Redis on Heroku
|
|
|
|
{% if cookiecutter.use_sentry == "y" %}
|
2015-07-28 23:23:46 +03:00
|
|
|
- Use sentry for error logging
|
2015-07-27 18:42:23 +03:00
|
|
|
{% endif %}
|
2015-07-28 23:23:46 +03:00
|
|
|
'''
|
2015-04-20 00:09:00 +03:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
|
|
|
from boto.s3.connection import OrdinaryCallingFormat
|
2015-04-26 08:45:48 +03:00
|
|
|
from django.utils import six
|
2015-07-28 23:23:46 +03:00
|
|
|
{% if cookiecutter.use_sentry == "y" %}
|
|
|
|
import logging
|
|
|
|
{% endif %}
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2015-04-20 15:31:55 +03:00
|
|
|
from .common import * # noqa
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2015-04-25 16:29:33 +03:00
|
|
|
# SECRET CONFIGURATION
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
2015-07-29 00:02:57 +03:00
|
|
|
# Raises ImproperlyConfigured exception if DJANGO_SECRET_KEY not in os.environ
|
2015-04-25 16:29:33 +03:00
|
|
|
SECRET_KEY = env("DJANGO_SECRET_KEY")
|
|
|
|
|
2015-04-20 00:09:00 +03:00
|
|
|
# This ensures that Django will be able to detect a secure connection
|
|
|
|
# properly on Heroku.
|
|
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
|
|
|
|
|
|
|
# django-secure
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
INSTALLED_APPS += ("djangosecure", )
|
2015-07-29 00:02:57 +03:00
|
|
|
{% if cookiecutter.use_sentry == "y" -%}
|
2015-07-27 18:42:23 +03:00
|
|
|
# raven sentry client
|
|
|
|
# See https://docs.getsentry.com/hosted/clients/python/integrations/django/
|
|
|
|
INSTALLED_APPS += ('raven.contrib.django.raven_compat', )
|
|
|
|
{%- endif %}
|
|
|
|
SECURITY_MIDDLEWARE = (
|
2015-04-20 00:09:00 +03:00
|
|
|
'djangosecure.middleware.SecurityMiddleware',
|
2015-07-27 18:42:23 +03:00
|
|
|
)
|
|
|
|
{% if cookiecutter.use_sentry == "y" -%}
|
|
|
|
RAVEN_MIDDLEWARE = ('raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware',
|
2015-07-28 23:23:46 +03:00
|
|
|
'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware',)
|
|
|
|
MIDDLEWARE_CLASSES = SECURITY_MIDDLEWARE + \
|
|
|
|
RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES
|
2015-07-28 19:02:41 +03:00
|
|
|
{% else %}
|
2015-07-27 18:42:23 +03:00
|
|
|
|
|
|
|
# Make sure djangosecure.middleware.SecurityMiddleware is listed first
|
|
|
|
MIDDLEWARE_CLASSES = SECURITY_MIDDLEWARE + MIDDLEWARE_CLASSES
|
|
|
|
|
2015-07-28 19:02:41 +03:00
|
|
|
{%- endif %}
|
2015-04-20 00:09:00 +03:00
|
|
|
|
|
|
|
# set this to 60 seconds and then to 518400 when you can prove it works
|
|
|
|
SECURE_HSTS_SECONDS = 60
|
2015-07-28 23:23:46 +03:00
|
|
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
|
|
|
|
"DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True)
|
2015-04-20 00:09:00 +03:00
|
|
|
SECURE_FRAME_DENY = env.bool("DJANGO_SECURE_FRAME_DENY", default=True)
|
2015-07-28 23:23:46 +03:00
|
|
|
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
|
|
|
|
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True)
|
2015-04-20 00:09:00 +03:00
|
|
|
SECURE_BROWSER_XSS_FILTER = True
|
|
|
|
SESSION_COOKIE_SECURE = False
|
|
|
|
SESSION_COOKIE_HTTPONLY = True
|
|
|
|
SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)
|
|
|
|
|
|
|
|
# SITE CONFIGURATION
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Hosts/domain names that are valid for this site
|
|
|
|
# See https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts
|
2015-09-01 21:18:28 +03:00
|
|
|
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['{{cookiecutter.domain_name}}'])
|
2015-04-20 00:09:00 +03:00
|
|
|
# END SITE CONFIGURATION
|
|
|
|
|
|
|
|
INSTALLED_APPS += ("gunicorn", )
|
|
|
|
|
|
|
|
# STORAGE CONFIGURATION
|
|
|
|
# ------------------------------------------------------------------------------
|
2015-04-26 12:57:45 +03:00
|
|
|
# Uploaded Media Files
|
|
|
|
# ------------------------
|
2015-04-20 00:09:00 +03:00
|
|
|
# See: http://django-storages.readthedocs.org/en/latest/index.html
|
|
|
|
INSTALLED_APPS += (
|
|
|
|
'storages',
|
|
|
|
)
|
2015-04-26 12:57:45 +03:00
|
|
|
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2015-04-24 15:12:34 +03:00
|
|
|
AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
|
|
|
|
AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY')
|
|
|
|
AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME')
|
2015-04-20 00:09:00 +03:00
|
|
|
AWS_AUTO_CREATE_BUCKET = True
|
|
|
|
AWS_QUERYSTRING_AUTH = False
|
|
|
|
AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat()
|
|
|
|
|
|
|
|
# AWS cache settings, don't change unless you know what you're doing:
|
|
|
|
AWS_EXPIRY = 60 * 60 * 24 * 7
|
2015-04-24 21:32:37 +03:00
|
|
|
|
|
|
|
# TODO See: https://github.com/jschneier/django-storages/issues/47
|
|
|
|
# Revert the following and use str after the above-mentioned bug is fixed in
|
|
|
|
# either django-storage-redux or boto
|
2015-04-20 00:09:00 +03:00
|
|
|
AWS_HEADERS = {
|
2015-04-26 08:45:48 +03:00
|
|
|
'Cache-Control': six.b('max-age=%d, s-maxage=%d, must-revalidate' % (
|
2015-04-26 08:10:06 +03:00
|
|
|
AWS_EXPIRY, AWS_EXPIRY))
|
2015-04-20 00:09:00 +03:00
|
|
|
}
|
|
|
|
|
2015-07-28 23:23:46 +03:00
|
|
|
# URL that handles the media served from MEDIA_ROOT, used for managing
|
|
|
|
# stored files.
|
2015-04-26 12:57:45 +03:00
|
|
|
MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
|
|
|
|
|
2015-09-17 14:09:26 +03:00
|
|
|
# Static Assets
|
2015-04-26 12:57:45 +03:00
|
|
|
# ------------------------
|
|
|
|
{% if cookiecutter.use_whitenoise == 'y' -%}
|
|
|
|
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
|
|
|
|
{% else %}
|
|
|
|
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
|
|
|
|
STATIC_URL = MEDIA_URL
|
|
|
|
|
|
|
|
# See: https://github.com/antonagestam/collectfast
|
2015-07-28 23:23:46 +03:00
|
|
|
# For Django 1.7+, 'collectfast' should come before
|
|
|
|
# 'django.contrib.staticfiles'
|
2015-04-26 12:57:45 +03:00
|
|
|
AWS_PRELOAD_METADATA = True
|
|
|
|
INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS
|
|
|
|
{%- endif %}
|
2015-04-20 00:09:00 +03:00
|
|
|
|
|
|
|
# EMAIL
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
|
|
|
|
default='{{cookiecutter.project_name}} <noreply@{{cookiecutter.domain_name}}>')
|
2015-07-06 21:23:12 +03:00
|
|
|
EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
|
2015-07-07 22:06:46 +03:00
|
|
|
MAILGUN_ACCESS_KEY = env('DJANGO_MAILGUN_API_KEY')
|
|
|
|
MAILGUN_SERVER_NAME = env('DJANGO_MAILGUN_SERVER_NAME')
|
2015-07-29 00:02:57 +03:00
|
|
|
EMAIL_SUBJECT_PREFIX = env("DJANGO_EMAIL_SUBJECT_PREFIX", default='[{{cookiecutter.project_name}}] ')
|
2015-07-16 12:10:36 +03:00
|
|
|
SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL)
|
2015-04-20 00:09:00 +03:00
|
|
|
|
|
|
|
# TEMPLATE CONFIGURATION
|
|
|
|
# ------------------------------------------------------------------------------
|
2015-07-28 23:23:46 +03:00
|
|
|
# See:
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
|
2015-05-08 05:13:49 +03:00
|
|
|
TEMPLATES[0]['OPTIONS']['loaders'] = [
|
|
|
|
('django.template.loaders.cached.Loader', [
|
2015-07-29 00:02:57 +03:00
|
|
|
'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ]),
|
2015-05-08 05:13:49 +03:00
|
|
|
]
|
2015-04-20 00:09:00 +03:00
|
|
|
|
|
|
|
# DATABASE CONFIGURATION
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
|
2015-04-24 06:37:50 +03:00
|
|
|
DATABASES['default'] = env.db("DATABASE_URL")
|
2015-04-20 00:09:00 +03:00
|
|
|
|
|
|
|
# CACHING
|
|
|
|
# ------------------------------------------------------------------------------
|
2015-07-06 13:43:26 +03:00
|
|
|
# Heroku URL does not pass the DB number, so we parse it in
|
|
|
|
CACHES = {
|
|
|
|
"default": {
|
|
|
|
"BACKEND": "django_redis.cache.RedisCache",
|
|
|
|
"LOCATION": "{0}/{1}".format(env.cache_url('REDIS_URL', default="redis://127.0.0.1:6379"), 0),
|
|
|
|
"OPTIONS": {
|
|
|
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
|
|
|
"IGNORE_EXCEPTIONS": True, # mimics memcache behavior.
|
|
|
|
# http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior
|
|
|
|
}
|
2015-04-20 00:09:00 +03:00
|
|
|
}
|
2015-07-06 13:43:26 +03:00
|
|
|
}
|
2015-04-20 00:09:00 +03:00
|
|
|
|
2015-07-27 18:42:23 +03:00
|
|
|
{% if cookiecutter.use_sentry == "y" %}
|
|
|
|
# Sentry Configuration
|
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',
|
|
|
|
'handlers': ['sentry'],
|
|
|
|
},
|
|
|
|
'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',
|
|
|
|
'handlers': ['console'],
|
|
|
|
'propagate': False,
|
|
|
|
},
|
|
|
|
'raven': {
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'handlers': ['console'],
|
|
|
|
'propagate': False,
|
|
|
|
},
|
|
|
|
'sentry.errors': {
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'handlers': ['console'],
|
|
|
|
'propagate': False,
|
|
|
|
},
|
2015-09-02 23:59:40 +03:00
|
|
|
'django.security.DisallowedHost': {
|
|
|
|
'level': 'ERROR',
|
|
|
|
'handlers': ['console', 'sentry'],
|
|
|
|
'propagate': False,
|
|
|
|
},
|
2015-07-27 18:42:23 +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
|
|
|
}
|
|
|
|
{% endif %}
|
2015-10-04 01:42:33 +03:00
|
|
|
# Custom Admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
|
2015-10-04 03:08:11 +03:00
|
|
|
ADMIN_URL = env('DJANGO_ADMIN_URL')
|
2015-10-04 00:54:29 +03:00
|
|
|
|
2015-04-20 00:09:00 +03:00
|
|
|
# Your production stuff: Below this line define 3rd party library settings
|