Skip to content

Instantly share code, notes, and snippets.

@mick-t
Last active August 29, 2015 14:00
Show Gist options
  • Save mick-t/11231602 to your computer and use it in GitHub Desktop.
Save mick-t/11231602 to your computer and use it in GitHub Desktop.
Django Settings file
# things I keep forgetting to do in new Django projects.
import os
# put settings common to all environment in a file called base.py:
from .base import *
# example here: https://github.com/twoscoops/django-twoscoops-project/tree/develop/project_name/project_name/settings
########## PATH CONFIGURATION
# sets the root of the project, useful for setting relative paths:
SITE_ROOT = os.path.realpath(os.path.dirname(__file__) + "/../")
# for example:
TEMPLATE_DIRS = (
# Don't forget to use absolute paths, not relative paths.
os.path.join(SITE_ROOT, 'templates'),
)
########## END PATH CONFIGURATION
########## VARIABLES FROM THE ENVIRONMENT
# put variables in the environment and then use this to retrieve them.
def get_env_variable(var_name):
""" Get the environment variable or return exception """
try:
return os.environ[var_name]
except KeyError:
error_msg = "Set the %s environment variable" % var_name
raise ImproperlyConfigured(error_msg)
# for example:
SECRET_KEY = get_env_variable('SECRET_KEY')
########## END VARIABLES FROM THE ENVIRONMENT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment