0

I cannot seem to deploy my Django application through gunicorn. Here is my Procfile:

web: gunicorn config.wsgi:application

My wsgi file is not located under the project, but under a config folder instead ./config/wsgi.py:

import os

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)

I'm using the heroku local tool to try to test this and I am running into this error:

$heroku local
forego | starting web.1 on port 5000
web.1  | [2015-11-22 10:05:29 -0800] [32081] [INFO] Starting gunicorn 19.3.0
web.1  | [2015-11-22 10:05:29 -0800] [32081] [INFO] Listening at: http://0.0.0.0:5000 (32081)
web.1  | [2015-11-22 10:05:29 -0800] [32081] [INFO] Using worker: sync
web.1  | [2015-11-22 10:05:29 -0800] [32084] [INFO] Booting worker with pid: 32084
web.1  | [2015-11-22 10:05:29 -0800] [32084] [ERROR] Exception in worker process:
web.1  |   __import__(module)
web.1  | hon2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
web.1  | [2015-11-22 10:05:29 -0800] [32084] [INFO] Worker exiting (pid: 32084)
web.1  | [2015-11-22 10:05:29 -0800] [32081] [INFO] Shutting down: Master
web.1  | [2015-11-22 10:05:29 -0800] [32081] [INFO] Reason: Worker failed to boot.

I've been trying to read about Procfile configurations and gunicorn for several hours and have tried different configurations of this, even trying to put the wsgi file under the application and changing the application name, all to no avail. This seems like something obvious that I am missing. Any ideas?

Updating with a little bit of my project structure below. It is based on the structure from Two Scoops of Django and can be found on the cookiecutter-django project.

base_dir/
 |application/
   |templates/
     |base.html
   |users/
     |views.py
     |model.py
   |...
   |other_apps/
 |config
   |wsgi.py
   |urls.py
   |settings/
     |common.py
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
TheGRS
  • 103
  • 8

2 Answers2

1

You have to let gunicorn listen to the port specified by the $PORT environment variable. I do something like this:

web: gunicorn -w 4 -b 0.0.0.0:$PORT app:app

I think you are probably calling all your modules correctly.

Robert Moskal
  • 21,737
  • 8
  • 62
  • 86
  • I think this is what I needed. I'm running into some other errors with whitenoise now, but the stacktrace is actually telling me something versus the extremely ambiguous error from earlier. I'll investigate a bit more tonight and let you know where I'm at. – TheGRS Nov 23 '15 at 04:01
  • Actually, I had forgotten to change the -w switch to 1 and was simply seeing 4 errors instead of 1. I am still seeing the same error as earlier this change unfortunately :/ – TheGRS Nov 23 '15 at 05:41
  • After some more digging I found that my settings were for production and thus local deployment was failing, your answer helped me figure this out, thank you! – TheGRS Nov 23 '15 at 06:33
1

Looks like Your config directory doesn't have a __init__.py file.

config must be a regular python module / package.

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49