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) # 项目入口