python烧瓶…我的计算机无法显示

python烧瓶…我的计算机无法显示,python,flask,Python,Flask,这是flask主页上的代码 from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run(host='0.0.0.0') app.run(debug=True) 当我运行代码时,输入 我的电脑无法显示。。。 问题出在哪里?1这不是烧瓶主页上的代码

这是flask主页上的代码

 from flask import Flask
 app = Flask(__name__)

 @app.route('/')
 def hello_world():
     return 'Hello World!'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
    app.run(debug=True)
当我运行代码时,输入 我的电脑无法显示。。。
问题出在哪里?

1这不是烧瓶主页上的代码

2调用run两次将不起作用。如果第一次运行将完成执行并进入第二次运行,那么第二次运行不会完成执行并进入程序的末尾并终止吗

app.run是这样的:

run(host=None, port=None, debug=None, **options)

Changed in version 0.10: The default port is now picked from the SERVER_NAME variable.

Parameters: 
host – the hostname to listen on. Defaults to '127.0.0.1'. 
       Set this to '0.0.0.0' to have the server available externally as well. 

port – the port of the webserver. Defaults to 5000 or the port defined in the SERVER_NAME config variable if present.
debug – if given, enable or disable debug mode. See debug.
options – the options to be forwarded to the underlying Werkzeug server. See werkzeug.serving.run_simple() for more information.
app.run(host='0.0.0.0')
您可以在一个app.run调用中设置所有这些参数

3从以下地址:

如果您[使用app.run]运行服务器,您会注意到 服务器只能从您自己的计算机访问,不能从任何其他计算机访问 在网络中。这是默认设置,因为在调试模式下,用户 应用程序的一部分可以在计算机上执行任意Python代码

如果已禁用调试或信任网络上的用户,则可以 只需更改 按如下方式运行方法:

run(host=None, port=None, debug=None, **options)

Changed in version 0.10: The default port is now picked from the SERVER_NAME variable.

Parameters: 
host – the hostname to listen on. Defaults to '127.0.0.1'. 
       Set this to '0.0.0.0' to have the server available externally as well. 

port – the port of the webserver. Defaults to 5000 or the port defined in the SERVER_NAME config variable if present.
debug – if given, enable or disable debug mode. See debug.
options – the options to be forwarded to the underlying Werkzeug server. See werkzeug.serving.run_simple() for more information.
app.run(host='0.0.0.0')
这会告诉您的操作系统在所有公共IP上侦听

如果尝试将主机设置为0.0.0.0,然后启动服务器,flask将显示以下消息:

正在运行按CTRL+C退出 但是,这并不意味着0.0.0.0是主机名=IP地址。0.0.0.0表示服务器正在侦听端口5000上的任何公共主机名=IP地址。网址http://localhost:5000 也会起作用


底线:除非您知道自己在做什么,否则不要使用主机0.0.0.0。

app.runhost='0.0.0.0',port=SERVER\u NAME,debug=none我这样更改了代码,并且定义了SERVER\u NAME=5000@asdfghj,举几个例子怎么样?如果我使用app.run,我可以使用url访问该页面http://localhost:5000/ 或者urlhttp://127.0.0.1:5000/; 但如果我在url中使用计算机的ip:http://123.456.12.34:5000/,我无法检索该页。另一方面,如果我使用app.runhost='0.0.0.0',我可以访问上面所有URL的页面。我意识到这是一篇老文章,但由于我偶然发现了它,然后找到了答案,我想我应该回复。关于DOCKER端口5000。要通过web浏览器从docker外部访问它,首先需要将端口从外部映射到内部。为此,启动docker,如下所示:docker run-p 5555:5000然后,您应该能够在映射的外部端口打开浏览器: