Skip to content Skip to sidebar Skip to footer

Getting Raise KeyError(key) KeyError: 'SECRET_KEY' With Django On Production Settings

I've 2 separate settings files for production and development and a common base.py settings file base.py SECRET_KEY = r'!@#$%^&123456' prod.py from .base import * SECRET_KEY

Solution 1:

I think you are trying this locally, and don't have the SECRET_KEY setup in your environment.

Set it using

export SECRET_KEY="somesecretvalue"

and then running python manage.py shell --settings=entri.settings.prod should work fine.


Solution 2:

I use os.getenv('SECRET_KEY'), instead of os.environ['SECRET_KEY']

print os.getenv('SECRET_KEY')    #returns None if KEY doesn't exist
print os.getenv('SECRET_KEY', 0) #will return 0 if KEY doesn't exist 

my python version is 2.7.12


Post a Comment for "Getting Raise KeyError(key) KeyError: 'SECRET_KEY' With Django On Production Settings"