nothingness nothingness - 6 months ago 40
Python Question

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

I changed my secret key to an environment variable on my Heroku app because that's bad but now locally it won't work.

I'm a few months into Django, and to programming period. I just found out deploying secret key to deployment was a security risk and changed it.

Now I want to develop locally but it will not work, how do I fix it?

Answer

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']