> For the complete documentation index, see [llms.txt](https://flask-yushu.gitbook.io/yushu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://flask-yushu.gitbook.io/yushu/3.-lan-tu-mo-xing-yu-codefirst/3.2-yong-lan-tu-zhu-ce-shi-tu-han-shu.md).

# 3.2 用蓝图注册视图函数

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

```python
# 实例化蓝图
# 第一个参数为蓝图所在模块名
# 应用名称
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

```python
def create_app():
    app = Flask(__name__)
    app.config.from_object("config")
    register_blueprint(app)

    return app


def register_blueprint(app):
    from app.web.book import web
    app.register_blueprint(web)
```
