Python “app.run(host='0.0.0.0')”在 Flask 中是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31904761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:43:22  来源:igfitidea点击:

What does "app.run(host='0.0.0.0') " mean in Flask

pythonwebtcpflaskserver

提问by Ding

I am reading the Flask documentation. I was told that with app.run(host='0.0.0.0'), I could make the server publicly available.

我正在阅读 Flask 文档。有人告诉我,使用app.run(host='0.0.0.0'),我可以使服务器公开可用。

What does it mean ? How can I visit the server in another computer (just localhost:5000in my own computer) ?

这是什么意思 ?如何访问另一台计算机上的服务器(仅localhost:5000在我自己的计算机上)?

回答by ipinak

To answer to your second question. You can just hit the IP address of the machine that your flask app is running, e.g. 192.168.1.100in a browser on different machine on the same networkand you are there. Though, you will not be able to access it if you are on a different network. Firewalls or VLans can cause you problems with reaching your application. If that computer has a public IP, then you can hit that IP from anywhere on the planet and you will be able to reach the app. Usually this might impose some configuration, since most of the public servers are behind some sort of router or firewall.

回答你的第二个问题。您只需点击您的烧瓶应用程序正在运行的机器的 IP 地址,例如192.168.1.100,在同一网络上不同机器上的浏览器中,您就在那里。但是,如果您在不同的网络上,您将无法访问它。防火墙或 VLans 可能会导致您无法访问您的应用程序。如果该计算机具有公共 IP,那么您可以从地球上的任何地方访问该 IP,并且您将能够访问该应用程序。通常这可能会强加一些配置,因为大多数公共服务器都在某种路由器或防火墙后面。