app01/views:
from flask import Blueprint user = Blueprint('user01', __name__, url_prefix='/admin') @user.route('/login') def login(): return '我是app01蓝图 登录'
app02/views:
from flask import Blueprint user = Blueprint('user02', __name__, url_prefix='/app') # url_prefix是用来隔离重名视图函数用的,视图函数前缀 @user.route('/login') def login(): return '我是app02蓝图 登录'
app.py
from flask import Flask from app01.views import user from app02.views import user as app02user # 防止蓝图对象重名,重命名 app = Flask(__name__) app.register_blueprint(user) # 注册蓝图,参数是蓝图对象 app.register_blueprint(app02user) if __name__ == '__main__': app.run()