10

My Problem:

When using gunicorn as my WSGI HTTP server, foreman fails to find the Django (wsgi?) application.

Application Structure:

In my Django application, I have things structured like this:

<git_repository_root>/
  <django_project_root>/
    <configuration_root>/

The <git_repository_root> contains the project management and deployment related things (requirements.txt, Procfile, fabfile.py, etc.)

The <django_project_root> contains my Django apps and application logic.

Finally, the <configuration_root> contains my settings.py and wsgi.py.

What I have tried:

My Procfile should look like this (according to the Heroku Docs):

web: gunicorn myapp.wsgi

When running foreman start with this project layout, I get an error:

ImportError: Import by filename is not supported.

What works:

If I move my Procfile from <git_repository_root> to <git_repository_root> it works locally. After pushing to Heroku (note: Heroku sees <git_repository_root>) I can't scale any workers / add processes. I get the following:

Scaling web dynos... failed
 !    No such process type web defined in Procfile.

I believe I want Procfile in my <git_repository_root> anyway though - so why isn't it working? I also tried changing the Procfile to: web: gunicorn myapp/myapp.wsgi

but no luck. Any help would be much appreciated!

1
  • 1
    Well phrased/documented question, btw. Commented Aug 7, 2013 at 5:17

2 Answers 2

4

Treat the entry in your Procfile like a bash command. You can cd into your <django_project_root> and then run the server.

For example, your Procfile (which should be in your <git_repository_root>) might look something like this:

web: cd <django_project_root> && gunicorn 
     --env DJANGO_SETTINGS_MODULE=<configuration_root>.settings 
     <configuration_root>.wsgi
Sign up to request clarification or add additional context in comments.

1 Comment

you perfectly got the question right and the solution provided was on point. A question since 2013 well phrased and answered
1

Move your Procfile back to <git_repository_root> and use:

web: gunicorn <django_project_root>.myapp:myapp

replacing the final "myapp" with your app's class name, presumably it is indeed "myapp".

... and read the error message: it is telling you that you can't import your worker class (app) by filename (myapp.wsgi), so of course saying dirname/myapp.wsgi won't work as well. You need a Python module:class syntax.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.