gpt4 book ai didi

python - 在 GCE 实例上运行 Web 应用程序

转载 作者:行者123 更新时间:2023-11-30 23:31:26 26 4
gpt4 key购买 nike

已关注 this教程,我正在学习如何使用 virtualenv 创建 RESTful python 服务和flask

我创建了一个小hello world Web 应用程序并执行它:./app.py 。结果是:

* Running on http://127.0.0.1:5000/
* Restarting with reloader

但是当我打开浏览器并输入http://<external ip>:5000时,而不是看到 hello world 我得到:

could not connect to <external ip>:5000

我错过了什么?

最佳答案

此消息清楚地说明了您缺少的内容:

Running on http://127.0.0.1:5000/

服务器仅监听localhost 地址,因此它不会看到来自其他计算机的连接。如果您想让服务器监听公共(public)接口(interface),您需要更改 app.run() 行,如下所示:

app.run(host = '0.0.0.0', debug = True)

关于python - 在 GCE 实例上运行 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19936799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com