I want to load some values in my Django settings file at the time of application startup, dynamically from the cloud, namely :
- Database password
- Database IP address
Is it a good practice to add python code to the settings file to retrieve these values from the cloud ?
I believe these will be loaded only once, at the time of application startup i.e. they won't adversely affect the performance of my application.
For instance :
# ~ settings.py ~
# retrieve data from the cloud, directly in the settings file
db_password = get_my_secrets()
db_ip_address = discover_db_ip()
# configure the database with these dynamic values
DATABASES = {
'default': {
'PASSWORD': db_password,
'HOST' : db_ip_address,
}
}
Here's a related article (shared by @Adiii) : Django Settings In the Cloud