Advertisement
mogra

Load Django environment from config file

Mar 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement