The name and port number of the server. Required for subdomain support
(e.g.: 'myapp.dev:5000') Note that localhost does not support
subdomains so setting this to “localhost” does not help. Setting a
SERVER_NAME also by default enables URL generation without a request
context but with an application context.
@app.route("/", subdomain="static")
def static_index():
"""Flask supports static subdomains
This is available at static.your-domain.tld"""
return "static.your-domain.tld"
@app.route("/dynamic", subdomain="<username>")
def username_index(username):
"""Dynamic subdomains are also supported
Try going to user1.your-domain.tld/dynamic"""
return username + ".your-domain.tld"
为了补充Sean Viera的post,还需要设置SERVER_NAME config变量。
文档:http://flask.pocoo.org/docs/config/#SERVER_NAME
要在本地进行测试,需要向
hosts
文件中添加条目,如下所示:所有Flask的路由构造都支持^{} 关键字参数(这包括对路由变量的支持)。
相关问题 更多 >
编程相关推荐