Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask Blueprint structure

Tags:

python

flask

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.

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.

like image 537
Theo Bouwman Avatar asked Nov 29 '25 20:11

Theo Bouwman


1 Answers

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.

# 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(...)
like image 169
jbasko Avatar answered Dec 01 '25 10:12

jbasko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!