蓝图被注册到应用后,所要执行的操作的集合,分配请求时,flask 会把蓝图和视图函数关联起来,并且生成两个端点之前的url
    蓝图可以极大的简化应用,拆分为不同模块

    app.py

    1. from flask import Flask
    2. import news,products
    3. app=Flask(__name__)
    4. app.route('/')
    5. def hello_word():
    6. return "hello word"
    7. app.register_blueprint(news.news_list)
    8. app.register_blueprint(products.products_list)
    9. if __name__ == '__main__':
    10. app.run()

    news.py

    1. from flask import Blueprint
    2. new_list=Blueprint('news',__name__)
    3. @new_list.route('/news')
    4. def new():
    5. return "this is news page"

    products.py

    1. from flask import Blueprint
    2. product_list=Blueprint('products',__name__)
    3. @product_list.route('/products')
    4. def product():
    5. return "this is product module"

    image.png
    image.png