Web进程在启动后60秒内无法绑定到$ PORT

joh*_*ual 4 python heroku flask

有人可以在Heroku上向我解释这条错误消息吗?应用程序在本地工作正常,但从未在网上成功

heroku[slug-compiler]: Slug compilation started
heroku[slug-compiler]: Slug compilation finished
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `python app.py ${PORT}`
app[web.1]:  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Run Code Online (Sandbox Code Playgroud)

该应用程序本身并不复杂

from flask import Flask, render_template
app = Flask(__name__, static_folder='static') 

@app.route('/')
def hello_world():
    return render_template('index.html')

if __name__ == '__main__':
    from os import environ
    app.run(debug=False, port=environ.get("PORT", 5000))
Run Code Online (Sandbox Code Playgroud)

bim*_*api 17

您需要指定host='0.0.0.0'app.run().除非另有说明,Flask绑定到"localhost",这意味着它不会绑定到外部可见的接口.

请参阅Flask - 配置dev服务器以在整个网络中可见