flask 路由规划(blueprint)

# 统一路由蓝牙规划
# file:blueprint_route.py
from flask import Blueprint

route_test = Blueprint("home",__name__)

# 路由只有通过app注册后才生效


"""
统一路由规划的优点:
统一前缀
当网站结构复杂后可维护
"""
@route_test.route("/")
def home():
    return "地址为:/home_page"
@route_test.route("/api")
def api():
    return "地址为:home_page/api"
# file:register_test.py

from flask import Flask
from blueprint_route import route_test                  # 导入蓝牙
app = Flask(__name__)                                   # 实例Flask应用
app.register_blueprint(route_test,url_prefix="/home")       # 蓝牙注册路由 统一前缀为home
if __name__=="__main__":
    app.run(host="0.0.0.0",debug=Ture)                  # 项目入口

 

posted @ 2019-06-09 17:51  jum_blog  阅读(910)  评论(0编辑  收藏  举报

载入天数...载入时分秒...