Sep 24, 2018 pip install django-generate-secret-key Then you will need to add it to the Django's INSTALLEDAPPS setting: INSTALLEDAPPS = (. ' djangogeneratesecretkey '. Sep 24, 2018 Django generate-secret-key application. Simple Django application that adds a new command. By default, the Signer class uses the SECRETKEY setting to generate signatures. You can use a different secret by passing it to the Signer constructor: signer = Signer ( 'my-other-secret' ) value = signer. Sign ( 'My string' ) value 'My string:EkfQJafvGyiofrdGnuthdxImIJw'.
This little app helps you to not commit your secrets to a repo and addsa nice way of exporting/importing secrets for a new deployment or automated testing with environment variables.
Though this never happened to me during coding, Travis had some problems to reliably execute the testsand hot load the new secrets, so I had move the secrets module into the my_secrets package to not havetwo modules named secrets. Python obviously cant handle that. Lesson learned after about 40 Travis builds. :(
django-secrets is working under Django 1.5+ and Python 2.7, 3.5 and 3.6
Installation
Usage
After installing the package please add it to your
INSTALLED_APPS
settings.Because we want to be able to hide our secret settings, we have to altermanage.py to run some code before the Django magic happens. Open
manage.py
and alter it like this:Now that the check is in place, run
manage.py
to initialize yourproject. This will create a new my_secrets package in your project root withthe following contents:The package also features a .gitignore file to prevent you from checkingin any secrets to git. Now open
definitions.py
to add your secretsto the list. Start with the Django secret key for example. When you aredone adding all secrets, run manage.py
again and you will be asked toenter your secrets.Now you can remove your secrets from
settings.py
and instead replacethem like this:Since the secrets are saved in a normal python package, you can just usethem the normal way including code completion, but now they are safe! :)
Secret Key Skin Care
Import / Export
This package adds a new management command:
export_secrets
. Thiswill print out export statements so you can easily create environmentvariables on a new machine and let the check
function do the restfor you, because it will also read in any known environment variables assecret values. This is quite handy for dynamically spawned instances orCI testing.Generate Secret Key Django App Download
Have fun and stay safe!