
蓝图是用于生成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")
一旦创建它,就可以通过使用该
register_blueprint函数在应用程序上“打动” -这在所指定的位置“打动”应用程序上的蓝图
url_prefix。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)