Skip to content

Reuse settings

Rostyslav Bryzgunov edited this page Apr 21, 2016 · 1 revision

Imagine that you have two Django settings:

# settings.py

SERVICE_DOMAIN = 'example.com'
SERVICE_URL = 'https://{}/service/'.format(SERVICE_DOMAIN)

And you want to use settings-overrider:

# settings.py

from settings_overrider import override

SERVICE_DOMAIN = 'example.com'
SERVICE_URL = 'https://{}/service/'.format(SERVICE_DOMAIN)

override(globals(), env='DJANGO_')

In this example, when you override SERVICE_DOMAIN (via DJANGO_SERVICE_DOMAIN env variable) - it will not automatically update SERVICE_URL setting. But you can do it:

from settings_overrider import override

SERVICE_DOMAIN = 'example.com'

external_settings = {}
override(external_settings, env='DJANGO_')
globals().update(external_settings)

if 'SERVICE_URL' not in external_settings:
    SERVICE_URL = 'https://{}/service/'.format(SERVICE_DOMAIN)
Clone this wiki locally