蓝图是用于生成web应用程序的“部分”的模板。
您可以将蓝图应用到多个地方的应用程序中。
每次应用它时,蓝图都会创建它的新版本
应用程序的石膏结构。
# An examplefrom flask import Blueprinttree_mold = Blueprint("mold", __name__)@tree_mold.route("/leaves")def leaves(): return "This tree has leaves"@tree_mold.route("/roots")def roots(): return "And roots as well"@tree_mold.route("/rings")@tree_mold.route("/rings/<int:year>")def rings(year=None): return "Looking at the rings for {year}".format(year=year)这是一个处理树的简单模型-它说任何应用程序
与树木打交道的人应该能接触到它的叶子、根和叶子
年轮。就其本身而言,它是一个中空的壳-它不能走,它不能走
回复,直到它在应用程序上留下深刻印象:
from tree_workshop import tree_moldapp.register_blueprint(tree_mold, url_prefix="/oak")app.register_blueprint(tree_mold, url_prefix="/fir")app.register_blueprint(tree_mold, url_prefix="/ash")
一旦创建了它,就可以通过使用
registeru blueprint函数-此函数“压印”图纸的模型
应用程序位于“urlu prefix”指定的位置。



