This one will be short and will be about keeping our sensitive data in a secure place instead of settings.py.
I will create a new folder under /etc and name it as crm_app_secret. Then create a file named config.json
cd /etc
sudo mkdir prj_crm_secret
sudo touch /etc/prj_crm_secret/config.json
Copy the SECRET_KEY from settings.py and paste in config.json like below.Then save it.
{
"SECRET_KEY":"pb))[email protected](pm4!uswdfwf6n_*+-(2-mg"
}
Similarly, you can add other sensitive info from settings.py such as usernames, passwords etc
We need to edit our settings.py like below to let config file to work
add these lines just after import os as you see below.
import os
import json
with open('/etc/prj_crm_secret/config.json') as config_file:
config = json.load(config_file)
In Settings.py, I need to declare that the value is in config file and add the dictionary key which I created in the config file
SECRET_KEY = config['SECRET_KEY’]
If you are getting username or password info from that config file, you need to use config.get not config only
EMAIL_USER = config.get('EMAIL_USER')