Forums

Error running WSGI application - The SECRET_KEY setting must not be empty.

Upon attempting to run the web app I'm getting the infamous error: The SECRET_KEY setting must not be empty. Yet the key appears to be stored in os.environ.

See: https://www.pythonanywhere.com/forums/topic/32701/#id_post_110924

What would be the cause for this if the variable can be accessed within Bash and the Python interpreter?

Error running WSGI application
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
File "/var/www/binnybit_pythonanywhere_com_wsgi.py", line 85, in <module>
from stackoverflow_clone.wsgi import application

File "/home/binnybit/django_stackoverflow/stackoverflow_clone/wsgi.py", line 16, in <module>
application = get_wsgi_application()

...
...

self.secret = self.secret or settings.SECRET_KEY
File "/home/binnybit/.virtualenvs/myvirtualenv/lib/python3.9/site-packages/django/conf/__init__.py", line 90, in 
__getattr__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")

Here's a rough idea of what project directory looks like

/django_stackoverflow
  -/stackoverflow_clone
     - __init__.py
     - settings.py
     - wsgi.py
     - urls.py
     - asgi.py
 manage.py

Did you follow https://help.pythonanywhere.com/pages/environment-variables-for-web-apps/ ?