3.2 用蓝图注册视图函数

1.在蓝图中注册视图函数

# 实例化蓝图
# 第一个参数为蓝图所在模块名
# 应用名称
web = Blueprint('web', __name__)


@web.route("/book/search/<q>/<page>")
def search(q, page):
    """
    搜索书籍路由
    :param q: 关键字 OR isbn
    :param page: 页码
    """
    isbn_or_key = is_isbn_or_key(q)
    if isbn_or_key == 'isbn':
        result = YuShuBook.search_by_isbn(q)
    else:
        result = YuShuBook.search_by_key(q)

    return jsonify(result)

2.蓝图是不能替代app应用的,在蓝图中注册了视图函数后,还需要将蓝图插入app

Last updated

Was this helpful?