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

前端 未结 3 1520
名媛妹妹
名媛妹妹 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:41

    You have to set your environmental variables in your development environment.

    Windows

    Go to Computer > Properties > Advanced System Settings.
    Go to the Advanced tab, and at the bottom there is an Environment Variables... button.

    In there you can edit the variables as you like.

    Linux

    Edit /etc/environment to include:

    SECRET_KEY = 
    

    or

    You should be using a virtual environment to isolate your system Python installation from your different projects (it solves conflicting version requirements) and to make deployment easier. Virtualenv Tutorial

    To activate your virtual environment when you want to use it there is a shell script located at /bin/activate that handles changing all the environmental variables that make the virtual environment work.

    Add:

    SECRET_KEY=''
    export SECRET_KEY
    

    to the bottom of the activate file and when it is run it will add (export) the environmental variable.

提交回复
热议问题