You can create a file named secret_settings.py
and place your SECRET_KEY
inside this file. Then add this file to .gitignore
.
Then in your settings, you can remove the secret key variable and import it from there. This should ensure that SECRET_KEY
variable remains out of version control.
Create a file named secret_settings
and then place your SECRET_KEY
and other secret settings in it.
SECRET_KEY = .. # add your setting here
Then in your settings.py
file, import these settings.
from secret_settings import *
Finally, add secret_settings.py
to your .gitignore
file.
Note:
If you already have committed some sensitive data to your repo, then change it!
As per Github website in the removing sensitive data article:
If you committed a password, change it! If you committed a key,
generate a new one.
Check this link on how to purge a file from your repository's history.