Last active
March 6, 2017 06:40
-
-
Save georgebyte/5214483 to your computer and use it in GitHub Desktop.
Django: Environment variable in Django settings
This file contains 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
# Load environment variable into Django settings. | |
# Usage: SOME_SECRET_KEY = get_env_variable("SOME_SECRET_KEY") | |
import os | |
from django.core.exceptions import ImproperlyConfigured | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment