Sun 17 Apr, 2022
With the idea that the project should be able to be made open-source at any moment without compromising security - here's how I have seperated settings.py from credentials such as db logins and secret keys.
touch:/etc/secrets/<example.jcaston.uk>/settings.ini
>> /etc/secrets/<example.jcaston.uk>/settings.ini:
[SECRETS]
SECRET_KEY=sEcrEtkEystrIng
...
[DATABASE]
DATABASE_ENGINE=django.db.backends.postgresql
DATABASE_NAME=dbname
DATABASE_USER=dbuser
DATABASE_PASSWORD=dbpassword
DATABASE_HOST=localhost
DATABASE_PORT=5432
[OTHER]
SOMETHING_ELSE=otherthing
ANOTHER_THING=anotherthing
...
>> settings/core.py:from configparser import RawConfigParser
...
config=RawConfigParser()
config.read('/etc/<example.jcaston.uk>/settings.ini')
...
...
...
SECRET_KEY=config.get('SECRETS', 'SECRET_KEY')
...
ANOTHER_THING=config.get('OTHER', 'ANOTHER_THING')
...
Caps does not matter in the .ini, just be consistent in how you are naming/referencing it.
blog.jcaston.uk // 2025