Flask开发中的虚拟服务器名称

是否可以在生产期间在flask中创建虚拟服务器名称?例如,我需要以下内容: if (months < 5) { return {'background-color': 'red'} }用于开发。

www.foo.com

这样的路线:

def main():
    app.run(debug=True,host='foo.com',port=8000)

将在@app.route('/bar/') def bar() -> str: return 'bar' 到达。 我尝试过更改配置:

foo.com/bar/

但是出现一个 OSError:[Errno 49]无法分配请求的地址

ttzz001 回答:Flask开发中的虚拟服务器名称

更改主机参数

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

它定义服务器将侦听的IP地址,而不是DNS。有关更多说明,请参见link

,

foo.com添加一个条目,指向您的开发PC主机文件中的本地IP(127.0.0.1)。例如,在Windows上,主机文件名为hosts,对于标准安装,该文件位于C:\Windows\System32\drivers\etc

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally,comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host


127.0.0.1 foo.com

开发后,您将可以在foo.com:8000上存储Flask页面。

本文链接:https://www.f2er.com/3136993.html

大家都在问