1

I have my project based on the django startproject: https://github.com/lincolnloop/django-startproject/

Here is my procfile:

web: gunicorn <myproject>.wsgi:application

Right now I have my set up like this:

[myproject]
---[conf]
------[local]
---------settings.py
------[qa]
---------settings.py

---[server_configs]
------[local]
---------django.wsgi
------[qa]
---------django.wsgi

My django.wsgi looks like this:

import os
import sys
import django.core.handlers.wsgi

sys.path.append('/app')
sys.path.append('/app/myproject')

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.conf.qa.settings'
application = django.core.handlers.wsgi.WSGIHandler()

I want to use the qa/django.wsgi for Heroku, but I am getting an error saying:

ImportError: No module named [myproject].wsgi

I have already gone through and tried solutions in this post: Configuring gunicorn for Django on Heroku but with no luck on my end.

Right now my PYTHONPATH is /app and have already tried Gunicorn+Django+Heroku. Python Path Issue with no luck either.

Community
  • 1
  • 1
Sam
  • 345
  • 5
  • 17
  • 1
    The gunicorn WSGI server does not support arbitrarily named files as a WSGI script file. It will only accept a file which is an importable module. Thus it has to have a .py extension. – Graham Dumpleton Mar 28 '14 at 00:32
  • Switched to using wsgi.py files and got the site to at least progress to the next error :) – Sam Mar 28 '14 at 02:43
  • Got the site up and running - moved the wsgi.py files under conf/qa and conf/local and then used this for my procfile: web: gunicorn conf.qa.wsgi:application. Thanks for the help! – Sam Mar 28 '14 at 03:31

2 Answers2

3

I had a similar problem once. Basically, you're running gunicorn from your root directory, but your wsgi is in [my_project]/[server_configs]/[qa]/.

There are two ways to go about it. If each of those directories has an init.py file, you can call it like a normal python module. Use:

web: gunicorn [myproject].[server_configs].[qa].django.wsgi:application

If they don't have init.py files (I didn't), you'll need your Procfile to switch into the proper directory. Try:

web: sh -c 'cd [server_configs]/[qa] && gunicorn django.wsgi:application'

Basically this is running a command in your shell to (1) change directories and (2) run gunicorn.

Alex
  • 8,321
  • 1
  • 34
  • 30
  • Still getting an error: ImportError: No module named wsgi. This is using your suggestion with the shell. – Sam Mar 28 '14 at 00:48
  • Just wanted to say that the second option, `cd`ing to the correct directory, worked for me. Thanks! (To anyone for whom it's not obvious, you shouldn't have the [square_brackets] around the elements in the paths.) – Phil Gyford Apr 28 '15 at 16:49
1

Heroku allows you to use environment variables in your Procfile. If you define an environment variable on Heroku, like so: heroku config:set WSGI_PATH=path/to/my/file/wsgi.py, then in your Procfile do: gunicorn $WSGI_PATH:application you should be good to go!

rdegges
  • 32,786
  • 20
  • 85
  • 109