Skip to content

Instantly share code, notes, and snippets.

@pelletier
Created August 22, 2010 16:51
Show Gist options
  • Save pelletier/543975 to your computer and use it in GitHub Desktop.
Save pelletier/543975 to your computer and use it in GitHub Desktop.
# projectfoo/config/__init__.py
from os import path
ROOT_PATH = path.dirname(path.dirname(path.abspath(__file__)))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Thomas Pelletier', 'thomas@pelletier.im'),
)
MANAGERS = ADMINS
TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = False
USE_L10N = False
MEDIA_ROOT = ''
MEDIA_URL = ''
ADMIN_MEDIA_PREFIX = '/media/'
SECRET_KEY = 'myawesomesecretkey'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'projectfoo.urls'
TEMPLATE_DIRS = (
'%s/templates' % ROOT_PATH,
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'projectfoo.killerapp',
)
# projectfoo/config/development.py
from os import path
DEBUG = True
ROOT_PATH = path.dirname(path.dirname(path.abspath(__file__)))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test-database.sqlite3',
}
}
MEDIA_ROOT = '%s/site_media/' % ROOT_PATH
MEDIA_URL = '/site_media/'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# And so on...
# projectfoo/config/production.py
from os import path
DEBUG = False
ROOT_PATH = path.dirname(path.dirname(path.abspath(__file__)))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'blah',
# ...
}
}
MEDIA_ROOT = '/var/data/projectfoo/media/'
MEDIA_URL = 'http://my-cdn.com/data/site_media/'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# And so on...
# projectfoo/settings.py
import os
# Set a default value for environements
default = 'development'
# Grab the current environement from the system environment variable named
# DJANGO_ENV
current_env = os.getenv('DJANGO_ENV', default=None)
# Print an alert if no value is found: better for debug
if current_env == None:
print "No DJANGO_ENV defined. Falling back to '%s'." % default
current_env = default
# Must match the config.(name) convention, so it must be lowercased and without
# dots in it. CURRENT_ENV is when you want to behave differently depending on
# which env you are running on.
CURRENT_ENV = current_env = current_env.lower()
if '.' in current_env:
raise Exception('You configuration environement must not contain a dot.')
# Finally import the configuration
exec("from config import *") # This is the base configuration
try:
exec("from config.%s import *" % current_env) # This is the specific
# configuration.
except ImportError:
print "The module 'config.%s' was not found. Only the base configuration\
has been imported." % current_env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment