DEV Community

Discussion on: How to deploy a Django App on Heroku in less than 5 minutes

Collapse
 
wavesailor profile image
wavesailor

Nice article but I lost you when you got to the section "Changing the secret key". Your tutorial was step by step and then I did not know where to changes these keys.

Collapse
 
jonatanvm profile image
Jonatan

So by default your settings file will have a line that looks like this:

SECRET_KEY = "some long random key"
Enter fullscreen mode Exit fullscreen mode

You need to change this key in production (for security), which is why you should change it to an environmental variable.

SECRET_KEY = os.getenv('SECRET_KEY', 'change-in-production')
Enter fullscreen mode Exit fullscreen mode

You can leave the default key to "change-in-production" as it will only be used in development.

After you have set your app to take it's SECRET_KEY from an environmental variable you need to set that environmental variable for your app on heroku. For this you need to download the Heroku CLI. After which you can set your apps environmental variables with the command:

 heroku config:set SECRET_KEY=very-long-secret-key
Enter fullscreen mode Exit fullscreen mode

You should replace "very-long-secret-key" with a very long password.