Last active
August 29, 2015 14:00
-
-
Save mick-t/11231602 to your computer and use it in GitHub Desktop.
Django Settings file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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