> 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.3-dan-lan-tu-duo-mo-kuai-chai-fen-shi-tu-han-shu.md).

# 3.3 单蓝图多模块拆分视图函数

蓝图，他的出发点，是为了分模块的。什么是模块级别的呢，比如一个web系统属于一个web模块；一个提供给移动端使用的api是一个api模块；一个内容管理系统是一个CMS。

我们不应该讲book,user这样的不同类别的py文件，做成多个蓝图（这样不是不行，只是小题大做了）

正确的方式是，在一个模块的初识文件中定义蓝图对象，这个模块的不同文件都引入这个蓝图对象来注册路由函数。并在模块的初始化文件中引入这些py文件来完成试图函数注册代码的执行

book.py

```python
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)
```

后面还会有user模块。我们这里先建立一段伪代码 user.py

```python
from . import web



@web.route("/user/login")
def login():
    return "success"
```

web/\_\_init\_\_.py

```python
from flask import Blueprint



web = Blueprint('web', __name__)

# 在这里导入不同文件，完成视图函数的注册
from app.web import book
from app.web import user
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://flask-yushu.gitbook.io/yushu/3.-lan-tu-mo-xing-yu-codefirst/3.3-dan-lan-tu-duo-mo-kuai-chai-fen-shi-tu-han-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
