Merge pull request #215 from pydanny/use-django-environ

Replace django-configuration with django-environ: Awesome effort by @theskumar
This commit is contained in:
Daniel Greenfeld 2015-04-19 17:05:15 -07:00
commit 2781fdc755
9 changed files with 370 additions and 393 deletions

View File

@ -24,7 +24,7 @@ Features
* For Django 1.7 * For Django 1.7
* Twitter Bootstrap_ 3 * Twitter Bootstrap_ 3
* AngularJS_ * AngularJS_
* Settings management via django-configurations_ * Settings management via django-environ_
* Registration via django-allauth_ * Registration via django-allauth_
* User avatars via django-avatar_ * User avatars via django-avatar_
* Procfile_ for deploying to Heroku * Procfile_ for deploying to Heroku
@ -35,7 +35,7 @@ Features
.. _Bootstrap: https://github.com/twbs/bootstrap .. _Bootstrap: https://github.com/twbs/bootstrap
.. _AngularJS: https://github.com/angular/angular.js .. _AngularJS: https://github.com/angular/angular.js
.. _django-configurations: https://github.com/jezdez/django-configurations .. _django-environ: https://github.com/joke2k/django-environ
.. _django-allauth: https://github.com/pennersr/django-allauth .. _django-allauth: https://github.com/pennersr/django-allauth
.. _django-avatar: https://github.com/jezdez/django-avatar/ .. _django-avatar: https://github.com/jezdez/django-avatar/
.. _Procfile: https://devcenter.heroku.com/articles/procfile .. _Procfile: https://devcenter.heroku.com/articles/procfile

View File

@ -19,8 +19,8 @@ Environment Variable Django Setting Development
DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error
DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error
DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error
DJANGO_CACHES CACHES locmem memcached DJANGO_CACHES CACHES (default) locmem memcached
DJANGO_DATABASES DATABASES See code See code DJANGO_DATABASES DATABASES (default) See code See code
DJANGO_DEBUG DEBUG True False DJANGO_DEBUG DEBUG True False
DJANGO_EMAIL_BACKEND EMAIL_BACKEND django.core.mail.backends.console.EmailBackend django.core.mail.backends.smtp.EmailBackend DJANGO_EMAIL_BACKEND EMAIL_BACKEND django.core.mail.backends.console.EmailBackend django.core.mail.backends.smtp.EmailBackend
DJANGO_SECRET_KEY SECRET_KEY CHANGEME!!! raises error DJANGO_SECRET_KEY SECRET_KEY CHANGEME!!! raises error
@ -99,7 +99,6 @@ Run these commands to deploy the project to Heroku:
heroku addons:add sendgrid:starter heroku addons:add sendgrid:starter
heroku addons:add memcachier:dev heroku addons:add memcachier:dev
heroku pg:promote DATABASE_URL heroku pg:promote DATABASE_URL
heroku config:set DJANGO_CONFIGURATION=Production
heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE
heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE
heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE
@ -139,7 +138,6 @@ You can then deploy by running the following commands.
ssh -t dokku@yourservername.com dokku memcached:link {{cookiecutter.repo_name}}-memcached {{cookiecutter.repo_name}} ssh -t dokku@yourservername.com dokku memcached:link {{cookiecutter.repo_name}}-memcached {{cookiecutter.repo_name}}
ssh -t dokku@yourservername.com dokku postgres:create {{cookiecutter.repo_name}}-postgres ssh -t dokku@yourservername.com dokku postgres:create {{cookiecutter.repo_name}}-postgres
ssh -t dokku@yourservername.com dokku postgres:link {{cookiecutter.repo_name}}-postgres {{cookiecutter.repo_name}} ssh -t dokku@yourservername.com dokku postgres:link {{cookiecutter.repo_name}}-postgres {{cookiecutter.repo_name}}
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_CONFIGURATION=Production
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE

View File

@ -2,10 +2,8 @@
django>=1.7.7,<1.8 django>=1.7.7,<1.8
# Configuration # Configuration
django-configurations==0.8 django-environ==0.3.0
django-secure==1.0.1 django-secure==1.0.1
django-cache-url==0.8.0
dj-database-url==0.3.0
# Forms # Forms
django-braces==1.4.0 django-braces==1.4.0

View File

@ -1,5 +1 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
from .local import Local # noqa
from .production import Production # noqa

View File

@ -8,20 +8,18 @@ https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/ https://docs.djangoproject.com/en/dev/ref/settings/
""" """
from __future__ import absolute_import, unicode_literals
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import environ
import os
from os.path import join, dirname
from configurations import Configuration, values APPS_DIR = environ.Path(__file__) - 1 # one folder back (/a/b/ - 2 = /a/)
ROOT_DIR = APPS_DIR - 1
BASE_DIR = dirname(dirname(__file__)) env = environ.Env()
# APP CONFIGURATION
class Common(Configuration): # ------------------------------------------------------------------------------
DJANGO_APPS = (
# APP CONFIGURATION
DJANGO_APPS = (
# Default Django apps: # Default Django apps:
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
@ -35,27 +33,27 @@ class Common(Configuration):
# Admin # Admin
'django.contrib.admin', 'django.contrib.admin',
) )
THIRD_PARTY_APPS = ( THIRD_PARTY_APPS = (
'crispy_forms', # Form layouts 'crispy_forms', # Form layouts
'avatar', # for user avatars 'avatar', # for user avatars
'allauth', # registration 'allauth', # registration
'allauth.account', # registration 'allauth.account', # registration
'allauth.socialaccount', # registration 'allauth.socialaccount', # registration
) )
# Apps specific for this project go here. # Apps specific for this project go here.
LOCAL_APPS = ( LOCAL_APPS = (
'users', # custom users app 'users', # custom users app
# Your stuff: custom apps go here # Your stuff: custom apps go here
) )
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
# END APP CONFIGURATION
# MIDDLEWARE CONFIGURATION # MIDDLEWARE CONFIGURATION
MIDDLEWARE_CLASSES = ( # ------------------------------------------------------------------------------
MIDDLEWARE_CLASSES = (
# Make sure djangosecure.middleware.SecurityMiddleware is listed first # Make sure djangosecure.middleware.SecurityMiddleware is listed first
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -63,94 +61,88 @@ class Common(Configuration):
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
) )
# END MIDDLEWARE CONFIGURATION
# MIGRATIONS CONFIGURATION # MIGRATIONS CONFIGURATION
MIGRATION_MODULES = { # ------------------------------------------------------------------------------
MIGRATION_MODULES = {
'sites': 'contrib.sites.migrations' 'sites': 'contrib.sites.migrations'
} }
# END MIGRATIONS CONFIGURATION
# DEBUG # DEBUG
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug # ------------------------------------------------------------------------------
DEBUG = values.BooleanValue(False) # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool("DJANGO_DEBUG", False)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
# END DEBUG
# SECRET CONFIGURATION # SECRET CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key # ------------------------------------------------------------------------------
# Note: This key only used for development and testing. # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# In production, this is changed to a values.SecretValue() setting # Raises ImproperlyConfigured exception if DJANO_SECRET_KEY not in os.environ
SECRET_KEY = 'CHANGEME!!!' SECRET_KEY = env("DJANGO_SECRET_KEY")
# END SECRET CONFIGURATION
# FIXTURE CONFIGURATION # FIXTURE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS # ------------------------------------------------------------------------------
FIXTURE_DIRS = ( # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
join(BASE_DIR, 'fixtures'), FIXTURE_DIRS = (
) str(APPS_DIR.path('fixtures')),
# END FIXTURE CONFIGURATION )
# EMAIL CONFIGURATION # EMAIL CONFIGURATION
EMAIL_BACKEND = values.Value('django.core.mail.backends.smtp.EmailBackend') # ------------------------------------------------------------------------------
# END EMAIL CONFIGURATION EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
# END EMAIL CONFIGURATION
# MANAGER CONFIGURATION # MANAGER CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins # ------------------------------------------------------------------------------
ADMINS = ( # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = (
("""{{cookiecutter.author_name}}""", '{{cookiecutter.email}}'), ("""{{cookiecutter.author_name}}""", '{{cookiecutter.email}}'),
) )
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS MANAGERS = ADMINS
# END MANAGER CONFIGURATION
# DATABASE CONFIGURATION # DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases # ------------------------------------------------------------------------------
DATABASES = values.DatabaseURLValue('postgres://localhost/{{cookiecutter.repo_name}}') # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
# END DATABASE CONFIGURATION DATABASES = {
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
'default': env.db("DATABASE_URL", default="postgres://localhost/{{cookiecutter.repo_name}}"),
}
DATABASES['default']['ATOMIC_REQUESTS'] = True
# CACHING
# Do this here because thanks to django-pylibmc-sasl and pylibmc
# memcacheify (used on heroku) is painful to install on windows.
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': ''
}
}
# END CACHING
# GENERAL CONFIGURATION # GENERAL CONFIGURATION
# ------------------------------------------------------------------------------
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = '{{ cookiecutter.timezone }}'
# Local time zone for this installation. Choices can be found here: # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name LANGUAGE_CODE = 'en-us'
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = '{{ cookiecutter.timezone }}'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
LANGUAGE_CODE = 'en-us' SITE_ID = 1
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
SITE_ID = 1 USE_I18N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
USE_I18N = True USE_L10N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_L10N = True USE_TZ = True
# END GENERAL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz # TEMPLATE CONFIGURATION
USE_TZ = True # ------------------------------------------------------------------------------
# END GENERAL CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
TEMPLATE_CONTEXT_PROCESSORS = (
# TEMPLATE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'allauth.account.context_processors.account', 'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount', 'allauth.socialaccount.context_processors.socialaccount',
@ -162,87 +154,87 @@ class Common(Configuration):
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request', 'django.core.context_processors.request',
# Your stuff: custom template context processors go here # Your stuff: custom template context processors go here
) )
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
TEMPLATE_DIRS = ( TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'), str(APPS_DIR.path('templates')),
) )
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader', 'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader', 'django.template.loaders.app_directories.Loader',
) )
# See: http://django-crispy-forms.readthedocs.org/en/latest/install.html#template-packs # See: http://django-crispy-forms.readthedocs.org/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = 'bootstrap3' CRISPY_TEMPLATE_PACK = 'bootstrap3'
# END TEMPLATE CONFIGURATION
# STATIC FILE CONFIGURATION # STATIC FILE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root # ------------------------------------------------------------------------------
STATIC_ROOT = join(os.path.dirname(BASE_DIR), 'staticfiles') # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(ROOT_DIR('staticfiles'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/' STATIC_URL = '/static/'
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = ( STATICFILES_DIRS = (
join(BASE_DIR, 'static'), str(APPS_DIR.path('static')),
) )
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = ( STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
) )
# END STATIC FILE CONFIGURATION
# MEDIA CONFIGURATION # MEDIA CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root # ------------------------------------------------------------------------------
MEDIA_ROOT = join(BASE_DIR, 'media') # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR('media'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
# END MEDIA CONFIGURATION
# URL Configuration # URL Configuration
ROOT_URLCONF = 'urls' # ------------------------------------------------------------------------------
ROOT_URLCONF = 'urls'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = 'wsgi.application' WSGI_APPLICATION = 'wsgi.application'
# End URL Configuration
# AUTHENTICATION CONFIGURATION # AUTHENTICATION CONFIGURATION
AUTHENTICATION_BACKENDS = ( # ------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', 'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend', 'allauth.account.auth_backends.AuthenticationBackend',
) )
# Some really nice defaults # Some really nice defaults
ACCOUNT_AUTHENTICATION_METHOD = 'username' ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory' ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
# END AUTHENTICATION CONFIGURATION # END AUTHENTICATION CONFIGURATION
# Custom user app defaults # Custom user app defaults
# Select the correct user model # Select the correct user model
AUTH_USER_MODEL = 'users.User' AUTH_USER_MODEL = 'users.User'
LOGIN_REDIRECT_URL = 'users:redirect' LOGIN_REDIRECT_URL = 'users:redirect'
LOGIN_URL = 'account_login' LOGIN_URL = 'account_login'
# END Custom user app defaults
# SLUGLIFIER # SLUGLIFIER
AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify' AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify'
# END SLUGLIFIER
# LOGGING CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging # LOGGING CONFIGURATION
# A sample logging configuration. The only tangible logging # ------------------------------------------------------------------------------
# performed by this configuration is to send an email to # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
# the site admins on every HTTP 500 error when DEBUG=False. # A sample logging configuration. The only tangible logging
# See http://docs.djangoproject.com/en/dev/topics/logging for # performed by this configuration is to send an email to
# more details on how to customize your logging configuration. # the site admins on every HTTP 500 error when DEBUG=False.
LOGGING = { # See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1, 'version': 1,
'disable_existing_loggers': False, 'disable_existing_loggers': False,
'filters': { 'filters': {
@ -264,11 +256,6 @@ class Common(Configuration):
'propagate': True, 'propagate': True,
}, },
} }
} }
# END LOGGING CONFIGURATION
@classmethod # Your common stuff: Below this line define 3rd party library settings
def post_setup(cls):
cls.DATABASES['default']['ATOMIC_REQUESTS'] = True
# Your common stuff: Below this line define 3rd party library settings

View File

@ -1,44 +1,54 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' '''
Local Configurations Local settings
- Runs in Debug mode - Runs in Debug mode
- Uses console backend for emails - Uses console backend for emails
- Use Django Debug Toolbar - Use Django Debug Toolbar
''' '''
from configurations import values
from .common import Common from .common import *
# DEBUG
# ------------------------------------------------------------------------------
DEBUG = env.bool('DJANGO_DEBUG', default=True)
TEMPLATE_DEBUG = DEBUG
# SECRET CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# Note: This key only used for development and testing.
SECRET_KEY = env("DJANGO_SECRET_KEY", 'CHANGEME!!!')
# Mail settings
# ------------------------------------------------------------------------------
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND',
default='django.core.mail.backends.console.EmailBackend')
class Local(Common): # CACHING
# ------------------------------------------------------------------------------
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': ''
}
}
# DEBUG # django-debug-toolbar
DEBUG = values.BooleanValue(True) # ------------------------------------------------------------------------------
TEMPLATE_DEBUG = DEBUG MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
# END DEBUG INSTALLED_APPS += ('debug_toolbar', 'django_extensions',)
# INSTALLED_APPS INTERNAL_IPS = ('127.0.0.1', '10.0.2.2',)
INSTALLED_APPS = Common.INSTALLED_APPS
# END INSTALLED_APPS
# Mail settings DEBUG_TOOLBAR_CONFIG = {
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_BACKEND = values.Value('django.core.mail.backends.console.EmailBackend')
# End mail settings
# django-debug-toolbar
MIDDLEWARE_CLASSES = Common.MIDDLEWARE_CLASSES + ('debug_toolbar.middleware.DebugToolbarMiddleware',)
INSTALLED_APPS += ('debug_toolbar', 'django_extensions',)
INTERNAL_IPS = ('127.0.0.1', '10.0.2.2',)
DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [ 'DISABLE_PANELS': [
'debug_toolbar.panels.redirects.RedirectsPanel', 'debug_toolbar.panels.redirects.RedirectsPanel',
], ],
'SHOW_TEMPLATE_CONTEXT': True, 'SHOW_TEMPLATE_CONTEXT': True,
} }
# end django-debug-toolbar
# Your local stuff: Below this line define 3rd party library settings # Your local stuff: Below this line define 3rd party library settings

View File

@ -7,124 +7,114 @@ Production Configurations
- Use sendgrid to send emails - Use sendgrid to send emails
- Use MEMCACHIER on Heroku - Use MEMCACHIER on Heroku
''' '''
from configurations import values from __future__ import absolute_import, unicode_literals
from .common import Common
class Production(Common): from boto.s3.connection import OrdinaryCallingFormat
# This ensures that Django will be able to detect a secure connection from .common import *
# properly on Heroku.
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# INSTALLED_APPS # This ensures that Django will be able to detect a secure connection
INSTALLED_APPS = Common.INSTALLED_APPS # properly on Heroku.
# END INSTALLED_APPS SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# SECRET KEY # django-secure
SECRET_KEY = values.SecretValue() # ------------------------------------------------------------------------------
# END SECRET KEY INSTALLED_APPS += ("djangosecure", )
# django-secure MIDDLEWARE_CLASSES = (
INSTALLED_APPS += ("djangosecure", )
# MIDDLEWARE CONFIGURATION
MIDDLEWARE_CLASSES = (
# Make sure djangosecure.middleware.SecurityMiddleware is listed first # Make sure djangosecure.middleware.SecurityMiddleware is listed first
'djangosecure.middleware.SecurityMiddleware', 'djangosecure.middleware.SecurityMiddleware',
) ) + MIDDLEWARE_CLASSES
MIDDLEWARE_CLASSES += Common.MIDDLEWARE_CLASSES # set this to 60 seconds and then to 518400 when you can prove it works
# END MIDDLEWARE CONFIGURATION 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)
# set this to 60 seconds and then to 518400 when you can prove it works # SITE CONFIGURATION
SECURE_HSTS_SECONDS = 60 # ------------------------------------------------------------------------------
SECURE_HSTS_INCLUDE_SUBDOMAINS = values.BooleanValue(True) # Hosts/domain names that are valid for this site
SECURE_FRAME_DENY = values.BooleanValue(True) # See https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts
SECURE_CONTENT_TYPE_NOSNIFF = values.BooleanValue(True) ALLOWED_HOSTS = ["*"]
SECURE_BROWSER_XSS_FILTER = values.BooleanValue(True) # END SITE CONFIGURATION
SESSION_COOKIE_SECURE = values.BooleanValue(False)
SESSION_COOKIE_HTTPONLY = values.BooleanValue(True)
SECURE_SSL_REDIRECT = values.BooleanValue(True)
# end django-secure
# SITE CONFIGURATION INSTALLED_APPS += ("gunicorn", )
# Hosts/domain names that are valid for this site
# See https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ["*"]
# END SITE CONFIGURATION
INSTALLED_APPS += ("gunicorn", ) # STORAGE CONFIGURATION
# ------------------------------------------------------------------------------
# STORAGE CONFIGURATION # See: http://django-storages.readthedocs.org/en/latest/index.html
# See: http://django-storages.readthedocs.org/en/latest/index.html INSTALLED_APPS += (
INSTALLED_APPS += (
'storages', 'storages',
) )
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID")
AWS_ACCESS_KEY_ID = values.SecretValue() AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY")
AWS_SECRET_ACCESS_KEY = values.SecretValue() AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME")
AWS_STORAGE_BUCKET_NAME = values.SecretValue() AWS_AUTO_CREATE_BUCKET = True
AWS_AUTO_CREATE_BUCKET = True AWS_QUERYSTRING_AUTH = False
AWS_QUERYSTRING_AUTH = False AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat()
# See: https://github.com/antonagestam/collectfast # See: https://github.com/antonagestam/collectfast
# For Django 1.7+, 'collectfast' should come before 'django.contrib.staticfiles' # For Django 1.7+, 'collectfast' should come before 'django.contrib.staticfiles'
AWS_PRELOAD_METADATA = True AWS_PRELOAD_METADATA = True
INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS
# AWS cache settings, don't change unless you know what you're doing: # AWS cache settings, don't change unless you know what you're doing:
AWS_EXPIRY = 60 * 60 * 24 * 7 AWS_EXPIRY = 60 * 60 * 24 * 7
AWS_HEADERS = { AWS_HEADERS = {
'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % ( 'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (
AWS_EXPIRY, AWS_EXPIRY) AWS_EXPIRY, AWS_EXPIRY)
} }
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html
try:
from boto.s3.connection import OrdinaryCallingFormat
AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat()
except ImportError:
pass
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
# END STORAGE CONFIGURATION
# EMAIL # EMAIL
DEFAULT_FROM_EMAIL = values.Value('{{cookiecutter.project_name}} <noreply@{{cookiecutter.domain_name}}>') # ------------------------------------------------------------------------------
EMAIL_HOST = values.Value('smtp.sendgrid.com') DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
EMAIL_HOST_PASSWORD = values.SecretValue(environ_prefix="", environ_name="SENDGRID_PASSWORD") default='{{cookiecutter.project_name}} <noreply@{{cookiecutter.domain_name}}>')
EMAIL_HOST_USER = values.SecretValue(environ_prefix="", environ_name="SENDGRID_USERNAME") EMAIL_HOST = env("DJANGO_EMAIL_HOST", default='smtp.sendgrid.com')
EMAIL_PORT = values.IntegerValue(587, environ_prefix="", environ_name="EMAIL_PORT") EMAIL_HOST_PASSWORD = env("SENDGRID_PASSWORD")
EMAIL_SUBJECT_PREFIX = values.Value('[{{cookiecutter.project_name}}] ', environ_name="EMAIL_SUBJECT_PREFIX") EMAIL_HOST_USER = env('SENDGRID_USERNAME')
EMAIL_USE_TLS = True EMAIL_PORT = env.int("EMAIL_PORT", default=587)
SERVER_EMAIL = EMAIL_HOST_USER EMAIL_SUBJECT_PREFIX = env("EMAIL_SUBJECT_PREFIX", default='[{{cookiecutter.project_name}}] ')
# END EMAIL EMAIL_USE_TLS = True
SERVER_EMAIL = EMAIL_HOST_USER
# TEMPLATE CONFIGURATION # TEMPLATE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs # ------------------------------------------------------------------------------
TEMPLATE_LOADERS = ( # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', ( ('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader', 'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader', 'django.template.loaders.app_directories.Loader',
)), )),
) )
# END TEMPLATE CONFIGURATION
# CACHING # DATABASE CONFIGURATION
# ------------------------------------------------------------------------------
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
DATABASES['defalut'] = env.db("DATABASE_URL")
# CACHING
# ------------------------------------------------------------------------------
try:
# Only do this here because thanks to django-pylibmc-sasl and pylibmc # Only do this here because thanks to django-pylibmc-sasl and pylibmc
# memcacheify is painful to install on windows. # memcacheify is painful to install on windows.
try:
# See: https://github.com/rdegges/django-heroku-memcacheify # See: https://github.com/rdegges/django-heroku-memcacheify
from memcacheify import memcacheify from memcacheify import memcacheify
CACHES = memcacheify() CACHES = memcacheify()
except ImportError: except ImportError:
CACHES = values.CacheURLValue(default="memcached://127.0.0.1:11211") CACHES = {
# END CACHING 'default': env.cache_url("DJANGO_CACHE_URL", default="memcache://127.0.0.1:11211"),
}
# Your production stuff: Below this line define 3rd party library settings # Your production stuff: Below this line define 3rd party library settings

View File

@ -3,9 +3,8 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.local")
os.environ.setdefault("DJANGO_CONFIGURATION", "Local")
from configurations.management import execute_from_command_line from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)

View File

@ -19,13 +19,12 @@ import os
# if running multiple sites in the same mod_wsgi process. To fix this, use # if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use # mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "{{ repo_name }}.settings" # os.environ["DJANGO_SETTINGS_MODULE"] = "{{ repo_name }}.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.production")
os.environ.setdefault("DJANGO_CONFIGURATION", "Production")
# This application object is used by any WSGI server configured to use this # This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION # file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here. # setting points here.
from configurations.wsgi import get_wsgi_application # noqa from django.core.wsgi import get_wsgi_application # noqa
application = get_wsgi_application() application = get_wsgi_application()
# Apply WSGI middleware here. # Apply WSGI middleware here.