Python Django Web应用程序无法使用Waitres服务器在Heroku上部署



我曾多次尝试在Heroku上部署我的django应用程序,最终成功了。它在localhost上运行良好,但是,当我使用heroku提供的链接时,页面上显示

应用程序错误应用程序中出现错误,无法提供您的页面。如果您是应用程序所有者,请查看日志以了解详细信息。您可以使用以下命令从Heroku CLI执行此操作heroku日志——尾部

然后我使用heroku日志--tail来查找错误,这就是

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

我相信问题从这里开始:

2020-11-04T11:18:46.124484+00:0 app[web.1]:bash:女服务员服务:未找到命令

这是我的Procfile设置:

web:女服务员服务--port=$port-ietwebsite.wsgi:应用程序

这是我的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()

这就是requirements.txt文件的

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

尝试将procfile更改为:

web gunicorn server.wsgi

请注意,服务器是django项目中的文件夹,因此应该保持不变。

尽管我使用的是Flask,但我对此的修复方法是,我没有用最近的安装更新我的requirements.txt文件。这样做,部署,它可能会起作用。

从项目的settings.py复制SECRET_KEY,登录到heroku,点击heroku面板上的应用程序。在"设置"下,单击"显示配置变量"。那里有一个密钥的占位符,在那里键入SECRET_key,然后将您的密钥粘贴为值。还记得在heroku的构建包设置中添加python。

如果不将SECRET_KEY添加到配置变量中,您的应用程序将被部署但不会加载。我已经浏览了你的requirements.txt文件和Procfile,我没有发现任何问题。此外,由于应用程序已成功部署,这很可能意味着前面提到的两个文件已按顺序排列。因此,将SECRET_KEY从settings.py复制到配置变量是很重要的,否则应用程序将无法加载。

最新更新