Django expects you to use environment variables in settings.py to adapt to multiple environments (e.g. local, heroku, AWS).
I assume that I should define, for example, the database username in the environment variable DB_USERNAME . How to read it?
import os DB_USERNAME = os.environ['DB_USERNAME'] DB_USERNAME = os.environ.get('DB_USERNAME') DB_USERNAME = os.environ.get('DB_USERNAME', 'john')
Should I grab KeyError and raise ImproperlyConfigured myself? I prefer the application to stop rather than launch it using the wrong settings (by default, people forgetting to set a variable, etc.).
In the case of default values, it may happen that john exists both by mistake and remotely, but with different permissions. It does not look very reliable.
source share