Specifying the project root when deploying to Heroku

My problem:

When using gunicorn as my WSGI HTTP server, the wizard cannot find the Django application (wsgi?).

Application structure:

In my Django application, I have things structured as follows:

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

<git_repository_root> contains project and deployment controls ( requirements.txt , Procfile , fabfile.py , etc.)

<django_project_root> contains my Django applications and application logic.

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

What I tried:

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

web: gunicorn myapp.wsgi

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

 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 clicking on Heroku (note: Heroku sees <git_repository_root> ), I cannot scale any worker / add processes. I get the following:

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

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

but no luck. Any help would be greatly appreciated!

+4
source share
2 answers

Move the Procfile back to <git_repository_root> and use:

 web: gunicorn <django_project_root>.myapp:myapp 

replacing the final "myapp" with your application class name, presumably this is really "myapp".

... and read the error message: it tells you that you cannot import your working class ( app ) by file name (myapp.wsgi), so of course dirname/myapp.wsgi will not work like Well. You need the syntax of Python module:class .

+1
source

Treat the entry in Procfile as bash. You can cd in <django_project_root> and then start 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 
0
source

Source: https://habr.com/ru/post/1495493/


All Articles