production.py 2.35 KB
Newer Older
1 2 3 4 5
"""Production settings and globals."""


from os import environ

Őry Máté committed
6
from base import *  # noqa
7 8 9 10 11 12 13 14 15 16 17


def get_env_setting(setting):
    """ Get the environment setting or return exception """
    try:
        return environ[setting]
    except KeyError:
        error_msg = "Set the %s env variable" % setting
        raise ImproperlyConfigured(error_msg)

########## HOST CONFIGURATION
Őry Máté committed
18 19
# See: https://docs.djangoproject.com/en/1.5/releases/1.5/
#      #allowed-hosts-required-in-production
20 21 22 23 24 25 26 27 28 29 30 31 32
ALLOWED_HOSTS = get_env_setting('DJANGO_ALLOWED_HOSTS').split(',')
########## END HOST CONFIGURATION

########## EMAIL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

try:
    # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host
    EMAIL_HOST = environ.get('EMAIL_HOST')
except ImproperlyConfigured:
    pass
else:
Kálmán Viktor committed
33
    # https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', '')

    # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
    EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', 'your_email@example.com')

    # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port
    EMAIL_PORT = environ.get('EMAIL_PORT', 587)

    # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
    EMAIL_USE_TLS = True

# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
EMAIL_SUBJECT_PREFIX = '[%s] ' % SITE_NAME

# See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
SERVER_EMAIL = EMAIL_HOST_USER
########## END EMAIL CONFIGURATION


########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
try:
    CACHES = {
Kálmán Viktor committed
57 58 59 60
        'default': {
            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
            'LOCATION': get_env_variable('DJANGO_MEMCACHED'),
        }
61 62 63
    }
except ImproperlyConfigured:
    CACHES = {
Kálmán Viktor committed
64 65 66 67
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': SITE_NAME,
        }
68 69 70 71 72 73 74 75
    }
########## END CACHE CONFIGURATION


########## SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = get_env_setting('SECRET_KEY')
########## END SECRET CONFIGURATION