# An example
from flask import Blueprint
tree_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)
An example of this would be Facebook. If Facebook used Flask, it might
have blueprints for the static pages (i.e. signed-out home, register,
about, etc.), the dashboard (i.e. the news feed), profiles
(/robert/about and /robert/photos), settings (/settings/security and
/settings/privacy) and many more. These components all share a general
layout and styles, but each has its own layout as well
蓝图是生成web应用程序“部分”的模板。你可以把它想象成一个模子:
您可以将蓝图应用到多个地方的应用程序中。每次应用时,蓝图将在应用程序的灰泥中创建其结构的新版本。
这是一个处理树的简单模型-它说任何处理树的应用程序都应该提供访问树的叶、根和环(按年)。就其本身而言,它是一个空心的壳-它不能路由,它不能响应,直到它被应用程序打动:
一旦创建了它,它就可以通过使用
register_blueprint
函数在应用程序上“印象深刻”——这将在url_prefix
指定的位置“印象深刻”应用程序上蓝图的模型。正如acomment by @Devasish中指出的,本文提供了一个很好的答案:
http://exploreflask.com/en/latest/blueprints.html
引用格罗姆的文章:
这是一个很好的解释,尤其是“如果Facebook使用了烧瓶”这一部分。它给了我们一个具体的场景来可视化蓝图的实际工作方式。
相关问题 更多 >
编程相关推荐