Django stores all the settings including the security hash, Database credentials and more in setting.py
. It offers easy to manage functions but creates difficulty in keeping the database credentials secret, using system dependent variables requires to edit the settings on every time the application is to be moved to new system, and setting.py
is not a file you can ignore in version control so changing it will break the version control.
The solution is simple, move these system variables to local settings file and create one of these local settings for each system the application is to be run, this helps to edit only the required settings and the local file can be exempted from the version control.
Django does not offer this function in the box, but is straight forward to implement:
- Add
local_settings.py
to your project, in the same directory wheresettings.py
is. - Import the
local_settings.py
to project.
To import add this to the end ofsettings.py
The try/except block informs Python to ignorestry: from local_settings import * except ImportError: pass
local_settings.py
in case it dose not exist. - Inform the version control to ignore the
local_settings.py
.
Including the local_settings.py
over rides the settings defined in the settings.py
and adds additional settings if any in the local settings.
Since local_settings.py
is not in version control any changes won't effect the version
Note : Make sure to document the settings in local_settings.py
or create local_settings.sample
as clone of local settings & add the sample to version control for record.
Last 5 Articles
All Articles >
-
DevOps Tools
-
The Best Marketing Apps to Use with Shopify
-
Tips to Increase Software Development Speed
-
Mitigating Risks In Custom Software Development
-
Container Security to Secure Microservices
News Letter
Subscribe to our email newsletter for useful tips and valuable resources, sent out every new article release.
Comments
Wow ! you have someting to tell us. That's great! Please keep in mind that comments are moderated, we employ
rel="nofollow"
for links, avoid using a spammy word or a domain in name field, it might end up as a Spam. Thanks for reading.