Created
October 26, 2015 14:25
-
-
Save neuroticnerd/3f4812077a7adcfbd4d8 to your computer and use it in GitHub Desktop.
Utility functions for Django settings.py
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
import os | |
# utility for getting settings from the environment | |
NOT_PROVIDED = object() | |
def env(key, default=NOT_PROVIDED, coerce=str): | |
if default is NOT_PROVIDED: | |
val = os.environ.get(key) | |
if val is None: | |
raise ValueError("Environment variable %s is required." % key) | |
else: | |
val = os.environ.get(key, default) | |
return coerce(val) if val is not None else val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment