Gun setup for Django on Heroku

I am trying to set up a Django test project on Heroku. Following the tips here and at the beginning of Heroku I'm trying to use gunicorn instead of the Django dev server.

This was my first attempt at Procfile:

 web: gunicorn_django --workers=4 --bind=0.0.0.0:$PORT my_project/settings.py worker: python my_project/manage.py celeryd -E -B --loglevel=INFO 

This gave me this error:

 ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named py 

I decided to choose a different track and follow the recommendations here . Now my Procfile looked like this:

 web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload my_project.settings 

(I also updated the requirements file to include gevent.) This gave me the same error:

 ImportError: Could not import settings 

Finally, I just set it to settings :

 web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload settings 

But now I get this error:

 Error: django project not found 

How my Django project is set up is that the settings.py file is in the parent repo directory - I don't have a Django project in another directory. It is at the same level as virtualenv and git files. Would this be a problem? I am sure that I am doing something simple - any help would be greatly appreciated.


If I follow the instructions from Heroku here and change the Procfile to this:

 web: gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT 

Nothing happens - there are no errors in the logs, but there are no processes, and the application just seems dead in the water.

+4
source share
4 answers

I just ran into this problem. In the procfile you copied from the Heroku tutorial, change hellodjango.wsgi to yourproject.wsgi

It seems that we all become a victim of blind copy-paste from time to time, but in your (and my) protection, there seems to be no * .wsgi file that actually opens, this is just how you signal that you want it to start django project.

+13
source

I had the exact same problem as yours. The way I was finally able to make it work was to use the django submachine gun.

I added gunicorn in django settings.py

 'gunicorn', 

Then I used this as my web entry in my Procfile.

 web: python manage.py run_gunicorn -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload 

You may need to modify the .manage.py file if you use a different directory structure than I did. My application was in / app, and my path to python was also / app.

+4
source

I had this problem and landed to point directly to the python path and then set the link preferences.

At the end, my Procfile looks like this:

 web: gunicorn_django --pythonpath=/app/project --settings=settings 

I had to run heroku run , which showed env variables, and where could I find the /app that I added to my project name.

+2
source

Do you have requirements.txt in the root folder (containing the word django ) as well as settings.py ? Those that appear to be Django application discovery requirements, as described here .

0
source

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


All Articles