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

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

    You can export your secret key as an environment variable locally.

    export SECRET_KEY=mysecretkey
    ./manage.py runserver
    

    Or you could change your settings.py to use a hardcoded secret key in DEBUG mode. If you do this, make sure you are running with DEBUG = False on Heroku.

    import os
    
    if DEBUG:
        SECRET_KEY = 'mysecretkey'
    else:
        SECRET_KEY = os.environ['SECRET_KEY']
    

提交回复
热议问题