Reputation: 2239
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!
Upvotes: 10
Views: 2102
Reputation: 2671
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
Upvotes: 4
Reputation: 13598
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.
Upvotes: 1