'Python Django Web application not able to deploy on Heroku using Waitress server

I have tried to deployed my django application several times on Heroku and then i finally succeeded . It is working fine on localhost ,however, when i use the link provided by heroku, the page says

Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail

i then use heroku logs --tail to find the errors and this is what comes up

2020-11-04T11:18:12.000000+00:00 app[api]: Build started by user ###@gmail.com
2020-11-04T11:18:37.568356+00:00 app[api]: Deploy 0f1e9788 by user ###@gmail.com
2020-11-04T11:18:37.568356+00:00 app[api]: Release v8 created by user ###@gmail.com
2020-11-04T11:18:37.580530+00:00 app[api]: Scaled to web@1:Free by user ###@gmail.com
2020-11-04T11:18:42.950948+00:00 heroku[web.1]: Starting process with command `waitress-serve --port=6549  ietwebsite.wsgi:application`
2020-11-04T11:18:46.124484+00:00 app[web.1]: bash: waitress-serve: command not found
2020-11-04T11:18:46.190476+00:00 heroku[web.1]: Process exited with status 127
2020-11-04T11:18:46.289712+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-04T11:18:46.293953+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-04T11:18:47.000000+00:00 app[api]: Build succeeded
2020-11-04T11:18:49.777532+00:00 heroku[web.1]: Starting process with command `waitress-serve --port=24388  ietwebsite.wsgi:application`
2020-11-04T11:18:51.662371+00:00 app[web.1]: bash: waitress-serve: command not found
2020-11-04T11:18:51.711684+00:00 heroku[web.1]: Process exited with status 127
2020-11-04T11:18:51.755205+00:00 heroku[web.1]: State changed from starting to crashed

I believe the issue starts from here:

2020-11-04T11:18:46.124484+00:00 app[web.1]: bash: waitress-serve: command not found

Here is my Procfile settings:

web: waitress-serve --port=$PORT ietwebsite.wsgi:application

And here is my wsgi.py:

import os
from django.core.wsgi import get_wsgi_application
from dotenv import load_dotenv

project_folder = os.path.expanduser('/ietwebsite/ietwebsite')  # adjust as appropriate
load_dotenv(os.path.join(project_folder, '.env'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ietwebsite.settings')
application = get_wsgi_application()

and this is what the requirements.txt file has

asgiref==3.3.0
astroid==2.4.2
autopep8==1.5.4
colorama==0.4.4
dj-database-url==0.5.0
Django==3.1.3
django-env-settings==1.1.0.0
django-heroku==0.3.1
django-waitress==0.1.0
gunicorn==20.0.4
isort==5.6.4
lazy-object-proxy==1.4.3
mccabe==0.6.1
psycopg2==2.7.7
pycodestyle==2.6.0
pylint==2.6.0
python-decouple==3.3
python-dotenv==0.15.0
pytz==2020.4
six==1.15.0
sqlparse==0.4.1
toml==0.10.2
typed-ast==1.4.1
waitress==1.4.4
whitenoise==5.2.0
wrapt==1.12.1


Solution 1:[1]

Try changing the procfile to this:

web gunicorn server.wsgi

Note that the server is the folder inside the django project so should remain the same.

Solution 2:[2]

Even though I'm using Flask, my fix for this was that I had not updated my requirements.txt file with my most recent installs. Do that, deploy, and it might work.

Solution 3:[3]

Copy the SECRET_KEY from settings.py of your project, sign in to heroku, click on the App on your heroku dashboard. Under settings click on reveal config vars. There is a placeholder for key there, type SECRET_kEY there and paste your key as the value. Also remember to add python in the buildpack settings of heroku. Without the SECRET_KEY added to the config variables, your application will be deployed but won’t load. I have gone through your requirements.txt file and Procfile, and I can’t spot any problems there. Also since the application was successfully deployed, it most likely means that the two aforementioned files are in order. Therefore it is important to copy the SECRET_KEY from your settings.py to the config variables else the app won’t load.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chinmay Datar
Solution 2 middleenglish
Solution 3