简体   繁体   English

烧瓶蓝图结构

[英]Flask Blueprint structure

I am using Blueprints to separate my api , admin and authentication , but in my API I want to separate users , groups and files for a better structure instead of just one routes file. 我正在使用Blueprints来分隔apiadminauthentication ,但是在我的API中,我想分隔usersgroupsfiles以获得更好的结构,而不仅仅是一个routes文件。

So my question is: is it possible to create a blueprint inside a blueprint? 所以我的问题是:是否可以在蓝图内部创建蓝图?

Or is there a better solution to accomplish my structure needs? 还是有更好的解决方案来满足我的结构需求?

Thanks in advance. 提前致谢。

You don't have to "nest" them to achieve what you want. 您无需“嵌套”它们即可实现所需。 You just need to create the Blueprint instance in one module and then import that instance in the multiple route files that you have for that blueprint. 您只需要在一个模块中创建“ Blueprint实例,然后将该实例导入到该蓝图所具有的多个路由文件中即可。

# api/blueprint.py
from flask import Blueprint
bp = Blueprint(__name__, __name__)

# api/users.py
from .blueprint import bp
@bp.route(...)

# api/groups.py
from .blueprint import bp
@bp.route(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM