I have a Django app deployed on IIS. I am currently working through Django's deployment checklist to secure the app. I have an environment variable with the SECRET_KEY
stored as the value. I am accessing the SECRET_KEY
with this:
SECRET_KEY = os.getenv('SECRET_KEY')
print(SECRET_KEY)
When I view the IIS hosted app, I get a 500 error. When I use runserver
to host the same app, the development server runs with no issues, and the SECRET_KEY
is printed out (and is therefore accessed from settings.py
). However, this issue occurs when the app is viewed in the browser:
ImproperlyConfigured("The SECRET_KEY setting must not be empty.") django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
How is the SECRET_KEY
empty if it's printed out in the command line?
Edit:
In case it helps, my wsgi.py looks like this:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myProject.settings")
application = get_wsgi_application()