1. 目录机构
─blue_print 项目(包)
├─static 静态文件夹
├─templates 模板文件夹
├─view 视图文件夹
│ └─auth.py 蓝图1
└─home.py 蓝图2
└─init.py 创建app文件
manage.py 启动app文件
2. 具体文件
2.1 init.py
from flask import Flask
from .view.auth import auth
from .view.home import homedef create_app():app = Flask(__name__)app.secret_key = 'kacsnolsanssADADSSs'@app.route('/index')def index():return 'index'# 蓝图算法app.register_blueprint(auth)app.register_blueprint(home)# url_prefix 给路由加上前缀# app.register_blueprint(auth, url_prefix='/web')# app.register_blueprint(home, url_prefix='/admin')return app
2.2 manage,py
from blue_print import create_appapp = create_app()if __name__ == '__main__':app.run()
2.3 蓝图1
from flask import Blueprint# 第一个参数撒名字
# 第一个参数名称自定义,第二个__name__
auth = Blueprint('my', __name__)@auth.route('/f1')
def f1():return 'f1'@auth.route('/f2')
def f2():return 'f2'
2.3 蓝图2
from flask import Blueprint
# 第一个参数名称自定义,第二个__name__
home = Blueprint('all', __name__)@home.route('/f3')
def f3():return 'f3'@home.route('/f4')
def f4():return 'f4'