Search code examples
python-3.xdjangoherokudjango-deployment

Problem with deploying Django app using Heroku


I am not clear with where to save Procfile in Django app for Heroku my app file structure is like this:

coding_site
   coding_site
      wsgi.py
      settings.py
   Procfile2
readME.md
Procfile1
other_files

should I save in Procfile1 or Procfile2 location?

my Procfile looks like this:

in location Procfile1

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

in Procfile2

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

Errors I got

Using Procfile1 location

2021-05-19T18:40:51.423744+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET 
path="/admin" host=coding-club-jaya.herokuapp.com request_id=71078218-39b0-4b7f-a817-7093078baa08 
fwd="123.201.77.16" dyno= connect= service= status=503 bytes= protocol=https

Using Procfile2 location

2021-05-19T17:49:21.981719+00:00 heroku[router]: at=error code=H14 desc="No web processes running" 
method=GET path="/admin" host=coding-club-jaya.herokuapp.com request_id=a47a58e6-4513-44a4-88aa-4425470d8465
fwd="123.201.77.16" dyno= connect= service= status=503 bytes= protocol=https

in btw:

I changed the settings.py file as shown in different tutorials

here are the changes made in the setting.py code

import django_heroku
import dj_database_url
***

MIDDLEWARE =[**, 'whitenoise.middleware.WhiteNoiseMiddleware', **]
***
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'ciba',
    }
}
***
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

os.makedirs(STATIC_ROOT, exist_ok=True)
os.makedirs(STATICFILES_DIRS[0], exist_ok=True)

# Activate Django-Heroku.
django_heroku.settings(locals())

in case needed here is my requirements.txt file


gunicorn==20.1.0
whitenoise==5.2.0
django-heroku==0.3.1

Django==3.0.2
requests==2.22.0
sqlparse==0.2.4
dj-database-url==0.5.0
dj-static==0.0.6
docopt==0.6.2
psycopg2
python-decouple
gitignore==0.0.8
pytz==2018.9
static3==0.7.0

When I checked log files in heroku I found this

2021-05-19T19:35:30.621629+00:00 app[web.1]: ModuleNotFoundError: No module named 'coding_site.settings'
2021-05-19T19:35:30.623811+00:00 app[web.1]: [2021-05-19 19:35:30 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-05-19T19:36:00.748054+00:00 app[web.1]: [2021-05-19 19:36:00 +0000] [4] [INFO] Shutting down: Master
2021-05-19T19:36:00.748553+00:00 app[web.1]: [2021-05-19 19:36:00 +0000] [4] [INFO] Reason: Worker failed to boot.

you might find it useful

Pls help, All my work is done and got stuck in the last step (it's the first time I am deploying)

Thank you!


Solution

  • As per the docs:

    "The Procfile must live in your app’s root directory. It does not function if placed anywhere else."

    That is the same directory where manage.py is.