我正在创建一个有3条主要路由的API。
我想在api2下有3条路线
因此,我检查有关嵌套Blueprint的烧瓶文档。
https://flask.palletsprojects.com/en/2.0.x/blueprints/#nesting-blueprints
我的代码是:
bp1 = Blueprint("api1", __name__, url_prefix="/api1")
bp2 = Blueprint("api2", __name__, url_prefix="/api2")
bp3 = Blueprint("api3", __name__, url_prefix="/api3")
bp2_1 = Blueprint("api2_1", __name__, url_prefix="/route1")
bp2_2 = Blueprint("api2_2", __name__, url_prefix="/route2")
bp2_3 = Blueprint("api2_3", __name__, url_prefix="/route3")
app.register_blueprint(bp1)
app.register_blueprint(bp3)
bp2.register_blueprint(bp2_1)
app.register_blueprint(bp2)当我运行它时,它会显示这个错误。
AttributeError: 'Blueprint' object has no attribute 'register_blueprint'水瓶还不支持嵌套蓝图吗?或者它开始支持嵌套蓝图的版本是什么?或者如何实现嵌套蓝图?
我使用的是1.1.2版本的烧瓶
发布于 2021-07-29 08:22:27
在注册应用程序的父母之前,你必须先注册孩子的蓝图。
bp2.register_blueprint(bp2_1)
bp2.register_blueprint(bp2_2)
bp2.register_blueprint(bp2_3)
app.register_blueprint(bp2)你可以在文档上找到更多的细节。
但我认为这是可能的,只有在瓶2.x。所以你必须升级你的版本。
https://stackoverflow.com/questions/68572428
复制相似问题