Web应用程序中的动态子域处理(Flask) [英] Dynamic Subdomain Handling in a Web App (Flask)
本文介绍了Web应用程序中的动态子域处理(Flask)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将使用flask来创建一个web应用程序,部分应用程序将涉及一个子域(例如,user1.appname.org)。
我不确定如何在瓶子配置中动态创建这些子域,或者如何将它们部署到生产服务器。
这样做的最好方法是什么?
解决方案
全部Flask的路由结构支持 子域
关键字参数(这包括对路由变量的支持)。
@ app.route (/,subdomain =static)
def static_index():
Flask支持静态子域名
static.your-domain.tld
返回static.your-domain.tld
@ app.route(/ dynamic,subdomain =< username>)
def username_index(username):
也支持动态子域名
尝试去user1.your-domain.tld / dynamic
返回用户名+.your-domain.tld
I'm going to be using flask to create a web application, and part of the application will involve a subdomain (for example, user1.appname.org).
I'm not sure how to go about creating these subdomains dynamically in the flask configuration, or how to deploy them to a production server.
What is the best way of doing this?
解决方案
All Flask's routing constructs support the subdomain
keyword argument (this includes support for route variables).
@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"
这篇关于Web应用程序中的动态子域处理(Flask)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文