# -*- coding: utf-8 -*-
"""
route 和 add_url_rule
route下边的装饰器 实际上是调了add_url_rule
route
method 请求方法
endpoint 别名 和url_for 配合使用
defaults 如果url没有参数 则可以使用这个作为默认值使用
redirect_to 重定向
subdomain 子域名
"""
from flask import Flask
app=Flask(__name__)
@app.route("/index",methods=["GET","POST"],endpoint="n1",defaults={"nid":888},redirect_to="/index2")
def index(nid):
return nid
@app.route("/index2",endpoint="n2",)
def index2(nid):
return nid
# 子域名 subdomain
"""
请求出去的时候 实际上要做域名解析 就是 域名和ip的匹配关系
window 中优先回去找 host文件 mac同理(/etc/hosts)
启动服务就可以 在浏览器 domain2.old.com:5000/user_index 的方式进行访问
"""
app.config["SERVER_NAME"]="old.com:5000"
# 一下是2中 子域名不同的写法
@app.route("/dynamic",subdomain="<domain>")
def static_index(domain):
return domain+".your-domain.tld"
@app.route("/user_index",subdomain="domain2")
def user_index(username):
return "static.your-domain.tld"
if __name__ == '__main__':
app.run()