1

I am trying to deploy my Django project with Heroku, and I know my Procfile is in the wrong location. But, when I move it to the correct directory, the app can't start.

I initially made the Procfile in my app directory instead of my project root directory, and when I try to move the Procfile to the root directory, I get a ModuleNotFoundError from wsgi.py regarding my settings file (I am using a settings folder to separate development and production settings files, so I made it a module, just FYI).

This is my Procfile:

web: gunicorn my_site.my_site.wsgi --log-file -

Here is my wsgi file:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_site.settings.production_settings')

application = get_wsgi_application()

Here is the error I get when I try to run heroku locally:

ModuleNotFoundError: No module named 'my_site.settings'

If I add another directory level to the to the location of my settings file (in wsgi.py):

'my_site.my_site.settings.production_settings'

I then get a new error about an app not being found in my INSTALLED_APPS in my settings. It seems that me changing the location of my Procfile somehow messes up all the directory extensions in my project, which doesn't make any sense. If I keep the Procfile in the original location, everything works, except I can't launch a dyno on heroku because the Procfile's original location isn't the root project directory.

EDIT Here is a pic of the directory structure: Where Procfile used to be Where Procfile is now

The Procfile used to be under 'my_site/my_site/my_site', but then I moved it to be under just 'my_site/'. Is this not the project root directory?

Walker Sorlie
  • 53
  • 1
  • 1
  • 7
  • I think [this question](https://stackoverflow.com/questions/16416172/how-can-i-modify-procfile-to-run-gunicorn-process-in-a-non-standard-folder-on-he) might help. – Alasdair Apr 24 '19 at 11:52
  • You should show your directory tree. Although I don't really understand what you mean about changing the location causing it to crash, since it wasn't working at all in the original location. – Daniel Roseman Apr 24 '19 at 13:28
  • @DanielRoseman, I added pictures of my directory tree. I guess crash isn't the best description. In the old location of the Procfile (under 'my_site/my_site/my_site') I could run the project locally with no problems. However, when I move the Procfile to the the new location (what I think is the project root directory, not totally clear on what that is exactly), I can't even run the server locally. – Walker Sorlie Apr 24 '19 at 16:40
  • EDIT: I followed the help that @Alasdair linked and it worked! I'm still curious as to what the project root directory is though – Walker Sorlie Apr 24 '19 at 16:48
  • Firstly, Heroku requires the Procfile to be in the (Heroku) app root (the outermost directory of the git repository). Next, you need the Django project directory (the one containing `manage.py`) to be on the Python path, so that `mysite.settings` and your Django apps can be imported. When your Heroku app root and Django project directory are the same, then the Django project directory is already on the Python path. In your case, your Django project is inside `mysite`, so you need to specify `pythonpath` in the gunicorn command in your Procfile. – Alasdair Apr 24 '19 at 18:35

0 Answers0