production.py 4.2 KB
Newer Older
1
# -*- coding: utf-8 -*-
Eliot Berriot's avatar
Eliot Berriot committed
2
"""
3
4
5
6
7
8
9
10
Production Configurations

- Use djangosecure
- Use Amazon's S3 for storing static files and uploaded media
- Use mailgun to send emails
- Use Redis on Heroku


Eliot Berriot's avatar
Eliot Berriot committed
11
"""
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import absolute_import, unicode_literals

from django.utils import six

from .common import *  # noqa

# SECRET CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# Raises ImproperlyConfigured exception if DJANGO_SECRET_KEY not in os.environ
SECRET_KEY = env("DJANGO_SECRET_KEY")

# django-secure
# ------------------------------------------------------------------------------
# INSTALLED_APPS += ("djangosecure", )
#
# SECURITY_MIDDLEWARE = (
#     'djangosecure.middleware.SecurityMiddleware',
# )
#
#
# # Make sure djangosecure.middleware.SecurityMiddleware is listed first
Eliot Berriot's avatar
Eliot Berriot committed
34
# MIDDLEWARE = SECURITY_MIDDLEWARE + MIDDLEWARE
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
# # set this to 60 seconds and then to 518400 when you can prove it works
# SECURE_HSTS_SECONDS = 60
# SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
#     "DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True)
# SECURE_FRAME_DENY = env.bool("DJANGO_SECURE_FRAME_DENY", default=True)
# SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
#     "DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True)
# 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
52
53
CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS

54
55
56
57
58
59
# END SITE CONFIGURATION

# STORAGE CONFIGURATION
# ------------------------------------------------------------------------------
# Uploaded Media Files
# ------------------------
Eliot Berriot's avatar
Eliot Berriot committed
60
DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"
61
62
63

# Static Assets
# ------------------------
Eliot Berriot's avatar
Eliot Berriot committed
64
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"
65
66
67
68
69

# TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------
# See:
# https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
Eliot Berriot's avatar
Eliot Berriot committed
70
71
72
73
74
75
76
77
TEMPLATES[0]["OPTIONS"]["loaders"] = [
    (
        "django.template.loaders.cached.Loader",
        [
            "django.template.loaders.filesystem.Loader",
            "django.template.loaders.app_directories.Loader",
        ],
    )
78
79
80
81
82
]

# CACHING
# ------------------------------------------------------------------------------
# Heroku URL does not pass the DB number, so we parse it in
83

84
85
86
87
88
89
90
91
92
93

# LOGGING CONFIGURATION
# ------------------------------------------------------------------------------
# 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
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
Eliot Berriot's avatar
Eliot Berriot committed
94
95
96
97
98
99
100
    "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"
101
102
        }
    },
Eliot Berriot's avatar
Eliot Berriot committed
103
104
105
106
107
108
109
110
111
112
    "handlers": {
        "mail_admins": {
            "level": "ERROR",
            "filters": ["require_debug_false"],
            "class": "django.utils.log.AdminEmailHandler",
        },
        "console": {
            "level": "DEBUG",
            "class": "logging.StreamHandler",
            "formatter": "verbose",
113
114
        },
    },
Eliot Berriot's avatar
Eliot Berriot committed
115
116
117
118
119
    "loggers": {
        "django.request": {
            "handlers": ["mail_admins"],
            "level": "ERROR",
            "propagate": True,
120
        },
Eliot Berriot's avatar
Eliot Berriot committed
121
122
123
124
        "django.security.DisallowedHost": {
            "level": "ERROR",
            "handlers": ["console", "mail_admins"],
            "propagate": True,
125
126
127
128
129
130
        },
    },
}


# Your production stuff: Below this line define 3rd party library settings