Flask - 配置dev服务器在网络中可见 [英] Flask - configure dev server to be visible across the network

查看:110
本文介绍了Flask - 配置dev服务器在网络中可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否是Flask特定的,但是当我在开发模式( http:// localhost:5000 )中运行应用程序时,我无法访问从网络上的其他机器( http:// [dev-host-ip]:5000 )。例如,在Rails在开发模式下,它工作正常。我找不到任何关于Flask dev服务器配置的文档。

I'm not sure if this is Flask specific, but when I run an app in dev mode (http://localhost:5000), I cannot access it from other machines on the network (with http://[dev-host-ip]:5000). With Rails in dev mode, for example, it works fine. I couldn't find any docs regarding the Flask dev server configuration. Any idea what should be configured to enable this?

推荐答案

添加参数到您的 app.run )。默认情况下,它在localhost上运行,更改为 app.run(host ='0.0.0.0'),在您的计算机IP地址上运行。

Add a parameter to your app.run(). By default it runs on localhost, change it to app.run(host= '0.0.0.0') to run on your machines IP address.

快速入门页面上的Flask网站上的外部可见服务器下记录


外部可见服务器

Externally Visible Server

如果您运行服务器您将注意到服务器只有
可从您自己的计算机,而不是从网络中的任何其他。
这是默认值,因为在调试模式下,
应用程序的用户可以在您的计算机上执行任意Python代码。如果
已禁用调试或信任您的网络上的用户,您可以使
的服务器公开可用。

If you run the server you will notice that the server is only available from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer. If you have debug disabled or trust the users on your network, you can make the server publicly available.

只需更改 run()方法如下:

app.run 0.0.0.0')

这会告诉您的操作系统监听公共IP。

This tells your operating system to listen on a public IP.

这篇关于Flask - 配置dev服务器在网络中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆