0

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()
OverflowingTheGlass
  • 2,324
  • 1
  • 27
  • 75
  • [This can be caused by a circular dependency](https://stackoverflow.com/questions/19128540/django-improperlyconfigured-the-secret-key-setting-must-not-be-empty). – Alasdair Nov 03 '17 at 14:53
  • 1
    I've seen those answers to similar questions, but i couldn't figure out how anything I was importing would cause that. – OverflowingTheGlass Nov 03 '17 at 14:56
  • After reading the comments on the question you provided more closely, I believe it's an error with deploying to IIS which requires creation of a DJANGO_SETTINGS_MODULE environment variable that has a value of myapp.settings. unsure of how to reconcile the two though. – OverflowingTheGlass Nov 03 '17 at 15:02
  • How are you setting the environment variable when you deploy? If you replace that line in your settings with `SECRET_KEY = 'supersecretkey'`, do you get the same error? – Alasdair Nov 03 '17 at 15:09
  • no - it works fine when the `SECRET_KEY` is hard coded. i'm setting the `SECRET_KEY` environment variable by adding a System environment variable through the control panel. I'm setting the `DJANGO_SETTINGS_MODULE` environment variable as an IIS environment variable for the FastCGI settings – OverflowingTheGlass Nov 03 '17 at 15:12

0 Answers0