我已经开发了一个使用flask框架的python应用程序,我在Heroku中部署相同但我在成功构建后遇到应用程序错误。我的应用程序在localhost中运行。问题是什么,我错了,以及如何解决问题。
Procfile内容:
web:python Flask / app.py,我也尝试过web:python app.py但它没有用。
Requirments.txt:
烧瓶== 0.12
更具体地说,我不使用gunicorn。
heroku中的LogFile详细信息:
Python app detected
-----> Installing python-2.7.13
$ pip install -r requirements.txt
Collecting flask==0.12 (from -r /tmp/build_ae4a1daf2328eb128abf7b576e0858c1/requirements.txt (line 1))
Downloading Flask-0.12-py2.py3-none-any.whl (82kB)
Collecting itsdangerous>=0.21 (from flask==0.12->-r /tmp/build_ae4a1daf2328eb128abf7b576e0858c1/requirements.txt (line 1))
Downloading itsdangerous-0.24.tar.gz (46kB)
Collecting Werkzeug>=0.7 (from flask==0.12->-r /tmp/build_ae4a1daf2328eb128abf7b576e0858c1/requirements.txt (line 1))
Downloading Werkzeug-0.12.1-py2.py3-none-any.whl (312kB)
Collecting Jinja2>=2.4 (from flask==0.12->-r /tmp/build_ae4a1daf2328eb128abf7b576e0858c1/requirements.txt (line 1))
Downloading Jinja2-2.9.5-py2.py3-none-any.whl (340kB)
Collecting click>=2.0 (from flask==0.12->-r /tmp/build_ae4a1daf2328eb128abf7b576e0858c1/requirements.txt (line 1))
Downloading click-6.7-py2.py3-none-any.whl (71kB)
Collecting MarkupSafe>=0.23 (from Jinja2>=2.4->flask==0.12->-r /tmp/build_ae4a1daf2328eb128abf7b576e0858c1/requirements.txt (line 1))
Downloading MarkupSafe-1.0.tar.gz
Installing collected packages: itsdangerous, Werkzeug, MarkupSafe, Jinja2, click, flask
Running setup.py install for itsdangerous: started
Running setup.py install for itsdangerous: finished with status 'done'
Running setup.py install for MarkupSafe: started
Running setup.py install for MarkupSafe: finished with status 'done'
Successfully installed Jinja2-2.9.5 MarkupSafe-1.0 Werkzeug-0.12.1 click-6.7 flask-0.12 itsdangerous-0.24
-----> Discovering process types
Procfile declares types -> web
-----> Compressing...
Done: 37.7M
-----> Launching...
Released v3
https://guarded-tundra-18526.herokuapp.com/ deployed to Heroku
LogFile不会显示任何错误。那么为什么我无法运行我的应用程序。
答案 0 :(得分:0)
这可能是Flask实例(app)的“run”方法的主机和端口参数的问题。
将主机设置为“0.0.0.0”而不是“127.0.0.1”以允许任何IP访问应用程序(而不是仅在本地)
默认情况下,该端口的容量为5000,但Heroku会动态地为应用程序分配一个端口,因此硬编码将无效。
按如下方式运行应用程序:
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host="0.0.0.0", port=port)
然后可以从Heroku PORT env var。
获取端口