March 2020
Intermediate to advanced
608 pages
17h 17m
English
To read sensitive settings from the environment variables, perform these steps:
# settings/_base.pyimport osfrom django.core.exceptions import ImproperlyConfigureddef get_secret(setting): """Get the secret variable or return explicit exception.""" try: return os.environ[setting] except KeyError: error_msg = f'Set the {setting} environment variable' raise ImproperlyConfigured(error_msg)
SECRET_KEY = get_secret('DJANGO_SECRET_KEY')DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': get_secret('DATABASE_NAME'), ...Read now
Unlock full access