在 Flask 中使用主机名而不是 ip 地址

Use a hostname with Flask rather than an ip-address

我在嵌入式设备 (运行ning linux) 中有一个 Flask 服务器,它同时具有 wifi 和有线以太网端口。我通过 192.168.101.1 上的 wifi 和 10.10.10.156 上的有线端口访问烧瓶服务器。

app.run(host="0.0.0.0", port=443, debug=False, ssl_context=context)

例如https://192.168.101.1/route1

我想使用主机名而不是 IP 地址。

例如https://my.device/route1

我该如何设置?我已经阅读了烧瓶 运行 '** options' 参数,但无法弄清楚,我也在 /etc/hosts 文件中进行了设置,但没有成功。

如果可能,您可以通过在每个客户端设备上配置 hosts 文件来进行设置。例如,在 linux 机器上,您的 /etc/hosts 文件中可能有:

192.168.101.1 my.device

这将导致客户端将 my.device 解析为 IP 地址 192.168.101.1。