使用flask的Blueprint进行蓝图路由规划

python yekong 42℃

创建文件api

from flask import Blueprint

route_api = Blueprint('api_page', __name__)


@route_api.route('/api1')
def index():
    return "api1"


@route_api.route('/api2')
def heello():
    return 'api2'

引入api文件

from flask import Flask
from api import route_api

app = Flask(__name__)
app.register_blueprint(route_api, url_prefix="/api")


@app.route('/')
def index():
    return "index"


if __name__ == "__main__":
    app.run()

将api文件注册到统一前缀api下

wanjunshijiecom 2021-08-21 at 06.19.51@2x

喜欢 (0)