SHARE
TWEET

Load Django environment from config file

mogra Mar 18th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CONFIG_INI = Path(os.environ.get('DJANGO_CONFIG_INI', BASE_DIR / 'config.ini'))
  2. if CONFIG_INI.exists():
  3.     config = RawConfigParser()
  4.     config.read_file(CONFIG_INI.open())
  5.     if not config.has_section('django'):
  6.         raise ImproperlyConfigured('Missing `django` section in environment file: %s', CONFIG_INI)
  7.     for k,v in config.items('django'):
  8.         e = k.upper()
  9.         if e not in os.environ: # Don't overwrite existing
  10.             os.environ[e] = v
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top