71👍
As @Graham Dumpleton stated in his answer, the OP’s problem could be solved by modifying his Procfile to the following:
web: gunicorn --pythonpath app app.wsgi
Why this works:
- Remember, that the Procfile is simply used by Heroku to start processes. In this case, gunicorn processes.
- Gunicorn’s
--pythonpath
argument allows you to dynamically attach a directory to the list of directories that the Python runtime searches for when do module look-ups. - By adding
--pythonpath app
to the gunicorn command, the interpreter was basically told ‘look inside of the app directory for a package (also) called app which contains a module called wsgi.`
The generic names of the folders in the OP’s question can obscure the syntax of the command, which is as follows:
gunicorn --pythonpath <directory_containing_package> <package>.<module>
More Info:
Gunicorn Documentation
- [Django]-Pycharm error Django is not importable in this environment
- [Django]-Manage.py runserver
- [Django]-How can I use redis with Django?
6👍
I made a ugly hack for getting this working. So I’m going to post my answer, but I hope you guys can come up with a better solution
Procfile
web: sh ./app/run.sh
app_project/app/run.sh
#!/bin/bash
cd app
gunicorn app.wsgi
- [Django]-Aggregate (and other annotated) fields in Django Rest Framework serializers
- [Django]-How to detect Browser type in Django?
- [Django]-How to select a record and update it, with a single queryset in Django?
5👍
If your file is nested in folders, the following will make more sense.
Instead of adding the path to the PYTHONPATH environmental variable, instead I referenced it like you would reference modules in a package:
In my case, the app object was in a scriptC.py, inside folderB, which is inside the folderA.
web: gunicorn folderA.folderB.scriptC:app
- [Django]-Django: How to set a field to NULL?
- [Django]-Validators = [MinValueValidator] does not work in Django
- [Django]-Test that user was logged in successfully