settings.py 692 B

1234567891011121314151617
  1. import os
  2. from .misc import yaml_coerce
  3. def get_settings_from_environment(prefix):
  4. """
  5. Django settings specific to the environment (eg. production) will be stored as environment variables
  6. prefixed with "PREFIX_", eg. prefix="UNTUBESETTINGS_"
  7. E.G. environment variables like UNTUBESETTINGS_SECRET_KEY=123, UNTUBESETTINGS_DATABASE="{'DB': {'NAME': 'db'}}"
  8. will be converted to pure Python dictionary with the prefix "UNTUBESETTINGS_" removed from the keys
  9. {
  10. "SECRET_KEY": 123,
  11. "DB": {'NAME': 'db'}
  12. }
  13. """
  14. prefix_len = len(prefix)
  15. return {key[prefix_len:]: yaml_coerce(value) for key, value in os.environ.items() if key.startswith(prefix)}