I added a SECRET_KEY config variable to my Django app on Heroku but now it won't work locally

前端 未结 3 1566
名媛妹妹
名媛妹妹 2021-01-15 02:59

I changed my secret key to an environment variable on my Heroku app. I changed it because I found out that keeping the secret key in settings.py was a security

3条回答
  •  感动是毒
    2021-01-15 03:35

    I had a bit of trouble working this out too, found my answer here: Set up your local environment variables

    If you are using heroku local to develop locally, this might work for you. I just needed to include this line in an .env file placed in the top directory with my Procfile:

    SECRET_KEY = 'yourkey'
    

    And in settings.py:

    os.environ.get('SECRET_KEY')
    

    This works great for me. Otherwise if for whatever reason you aren't using heroku local, maybe you could try importing your key from another file when working locally (and placing this file in your gitignore), and swapping back to the heroku config variable for deployment.

提交回复
热议问题