Web 应用程序中的动态子域处理(Flask) [英] Dynamic Subdomain Handling in a Web App (Flask)

查看:30
本文介绍了Web 应用程序中的动态子域处理(Flask)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用flask 创建一个Web 应用程序,该应用程序的一部分将涉及一个子域(例如,user1.appname.org).

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?

推荐答案

所有 Flask 的路由结构都支持 subdomain 关键字参数(包括对路由变量的支持).

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屋!

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