其他分享
首页 > 其他分享> > 05 flask 蓝图

05 flask 蓝图

作者:互联网

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()

 

标签:__,Blueprint,05,flask,app,蓝图,user,import
来源: https://www.cnblogs.com/lccode/p/14197931.html