简体   繁体   English

在 Heroku 上运行 python flask 应用程序失败

[英]Running a python flask app on Heroku fails

I have a python web app that I can successfully run on my local machine with this command我有一个 python web 应用程序,我可以使用此命令在本地计算机上成功运行

python run.py

I have successfully deployed the code to Heroku, but when I go to my application URL I get this error message that says我已成功将代码部署到 Heroku,但是当我将 go 部署到我的应用程序 URL 时,我收到此错误消息

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

Looking at the log tails yields查看日志尾部产量

 heroku logs --tail                            ✘ 2 

› Error: Missing required flag: › -a, --app APP app to run command against › 错误:缺少必需的标志: › -a, --app APP 运行命令的应用程序

My Procfile contains我的 Procfile 包含

web: python --app monte-carlo-retirement run.py

where monte-carlo-retirement is the name of my app其中 monte-carlo-retirement 是我的应用程序的名称

You're conflating two things.你把两件事混为一谈。

The error about a missing -a or --app argument is related to running the heroku CLI locally .有关缺少-a--app参数的错误与本地运行heroku CLI有关。 Instead of just heroku logs --tail , try heroku logs --app=monte-carlo-retirement --tail .而不是仅仅heroku logs --tail ,尝试heroku logs --app=monte-carlo-retirement --tail This should give you useful log output.这应该会给你有用的日志 output。

See also How does `heroku config` know what app to use?另请参阅`heroku config` 如何知道要使用什么应用程序? and How to avoid the --app option with heroku CLI?以及如何使用 heroku CLI 避免 --app 选项? . .

Your Procfile doesn't need that argument.您的Procfile不需要该参数。 You deploy your code to a particular app, so there is no confusion about what app it applies to.您将代码部署到特定应用程序,因此不会混淆它适用于哪个应用程序。 Furthermore, you are giving that argument to python where it is meaningless.此外,您将该论点提供给python毫无意义。

Take it out of your Procfile :把它从你的Procfile中取出:

web: python run.py

Then commit and redeploy.然后提交并重新部署。

Now, you haven't shown us what is in your run.py , but this would be a weird way to run it in production.现在,您还没有向我们展示您的run.py中的内容,但在生产环境中运行它会是一种奇怪的方式。 A more common approach would be to use something like Gunicorn .更常见的方法是使用类似Gunicorn的东西。

Install it locally and add it to your requirements.txt (if you are using pip ) or Pipfile / Pipfile.lock (if you are using Pipenv).在本地安装并将其添加到您的requirements.txt (如果您使用的是pip )或Pipfile / Pipfile.lock (如果您使用的是 Pipenv)。 Then modify your Procfile again to something like然后再次将您的Procfile修改为类似

web: gunicorn run:app

where app is the name of the Flask object in run.py .其中app是 run.py 中run.py object 的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM