3.3 单蓝图多模块拆分视图函数
from flask import jsonify
from helper import is_isbn_or_key
from yushu_book import YuShuBook
# 引入web模块
from . import web
@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)Last updated
Was this helpful?