Skip to content

Instantly share code, notes, and snippets.

@neuroticnerd
Created October 26, 2015 14:25
Show Gist options
  • Save neuroticnerd/3f4812077a7adcfbd4d8 to your computer and use it in GitHub Desktop.
Save neuroticnerd/3f4812077a7adcfbd4d8 to your computer and use it in GitHub Desktop.
Utility functions for Django settings.py
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