【flask】子域名的配置与使用

By Heanny
2020-04-19
1714 read

配置文件

config.py配置文件添加

SESSION_COOKIE_DOMAIN ='my.heanny.cn'
SERVER_NAME = 'my.heanny.cn'

该域名为默认域名

视图

配置默认使用的域名:

app.url_map.default_subdomain='www'

单独配置静态文件的路由(不然全炸)

__init__.py内容

app = Flask(__name__, template_folder='./templates', static_url_path='', static_folder=None,subdomain_matching=True)
app.config.from_object('config')
app.url_map.default_subdomain='www'
app.static_url_path = "/static"
app.static_folder = "static"
app.add_url_rule(app.static_url_path + '/<path:filename>',
                  endpoint='static',
                  view_func=app.send_static_file,
                  subdomain="static")

view.py中编辑内容

动态子域名,

subdomain="<subdomain>"为动态子域名
注意要添加泛解析

@app.route("/", subdomain="<subdomain>")
def dynamic_subdomain_all(subdomain):
    return subdomain + " .domain.all"

@app.route("/dynamic", subdomain="<subdomain>")
def dynamic_subdomain(subdomain):
    return subdomain + " .domain"


@app.route('/')
def index():
    return redirect('/index.html')

效果:


(ps:因为我没有泛域名的ssl证书,所以没有使用0.0)

静态子域名
@app.route("/", subdomain="admin")
def static_domain():
    return "static domain"


关于centos7使用php当中遇到的问题
【树莓派】centos系统扩展tf剩余空间

Comments

暂无评论,还不快来坐沙发...

Leave a Reply