I like having a command to generate a secret key, and the idea of a secret key file. However I think that automatically generating the secret key is going to lead to footgun-ey behavior. This mentions N=1 deployments, however it doesn't account for migrations or the like. RandomKeygen is a free mobile-friendly tool that offers randomly generated keys and passwords you can use to secure any application, service or device. KEY RandomKeygen - The Secure Password & Keygen Generator.
Djecrety is a Django secret key generator. This is a web tool to generate SECRETKEY and also have a Django package that does this simply with a command. Djecrety is a Django secret key generator. This is a web tool to generate SECRETKEY and also have a Django package that does this simply with a.
Simple Django application that adds a new command:
This will generate a new file secretkey.txt
containing a random Django secretkey. In your production settings file, replace the hardcoded key by:
You can avoid hardcoding the path of the key by using:
You can install this package from PyPi:
Then you will need to add it to the Django's INSTALLED_APPS setting:
You can now use
Run this command once in your local environment, and every time you deploy your app (on the remote host), to make sure the file exists.