用Heroku部署Flask [英] Deploying Flask with Heroku
问题描述
2013-06-06我试图在Heroku上部署一个Flask应用程序-23T11:23:59.264600 + 00:00 heroku [web.1]:错误R10(引导超时) - > Web进程无法在启动60秒内绑定到$ PORT
我不确定要尝试什么,我已经尝试将端口从5000更改为33507,但无济于事。我的Procfile如下所示:
web:python main.py
$
$ b $main.py
是启动服务器的主要Flask文件。
谢谢。
解决方案在Heroku上托管的Flask应用程序中,我使用以下代码启动服务器:
如果已定义,绑定到PORT,否则默认为5000.
$ prefid =lang -py prettyprint-override>if __name__ =='__main__' b port = int(os.environ.get('PORT',5000))
app.run(host ='0.0.0.0',port = port)
在本地开发时,将使用端口5000,在生产中Heroku将设置 PORT
环境变量。 (注意:默认情况下,Flask只能从你自己的计算机上访问,而不能从网络上的任何其他计算机上访问(参见 )。 )。设置 host ='0.0.0.0'
将使得Flask可从网络获得)
I'm trying to deploy a Flask app to Heroku however upon pushing the code I get the error
2013-06-23T11:23:59.264600+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
I'm not sure what to try, I've tried changing the port from 5000 to 33507, but to no avail. My Procfile looks like this:
web: python main.py
main.py
is the main Flask file which initiates the server.
Thanks.
In my Flask app hosted on Heroku, I use this code to start the server:
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
When developing locally, this will use port 5000, in production Heroku will set the PORT
environment variable.
(Side note: By default, Flask is only accessible from your own computer, not from any other in the network (see the Quickstart). Setting host='0.0.0.0'
will make Flask available from the network)
这篇关于用Heroku部署Flask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!