4

There are three files in my settings folder:

  • base.py
  • development.py
  • production.py

I've put this line in my wsgi.py file:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproj.settings.development")

But when I run gunicorn myproj.wsgi:application and try to load application in browser I get:

ImproperlyConfigured: The SECRET_KEY setting must not be empty.

I definitely have SECRET_KEY in base.py and in development.py I have this line:

from base import *

I've updated manage.py and specified new settings file there just to test if runserver will work and it works.

UPDATE: And now I have put SECRET_KEY into development.py. When I run gunicorn myproj.wsgi:application --settings 'myproj.settings.development' the error is still there.

Dmitrii Mikhailov
  • 5,053
  • 7
  • 43
  • 69

1 Answers1

15

Just needed to run :

gunicorn myproj.wsgi:application --env DJANGO_SETTINGS_MODULE='myproj.settings.development'

There's a line

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "videotube.settings.development")

in my wsgi.py. I don't know why but gunicorn doesn't care about it.

Dmitrii Mikhailov
  • 5,053
  • 7
  • 43
  • 69
  • Strange..I'm having the same issue but I have an environment variable specified in /etc/environment for DJANGO_SETTINGS_MODULE and SECRET_KEY. When I run the project with the development server it runs fine and picks up the secret key. Maybe gunicorn is unable to read the environment file? – wjh18 Sep 04 '19 at 01:45