0
votes

What is the properly flask-way to implement application with coupled blueprints?

I'm currently working on project with several modules. I've separate application into modules logically, in dependence of database entities, and specify these modules as blueprints. But some of these blueprints have dependencies on each other: for example, view of blueprint A uses internal method (like a search in db, not view) from blueprint B, while another view from B uses another internal method from A.

Of course, it's cause circular imports.

1
No.Order is important is should not get circular lock IMONava

1 Answers

0
votes

The best way to handle this would to be decouple your internal Blueprint calls into a separate module. Try to concentrate your database logic in one module and only create specific calls when needed.

Your project layout might look like:

+ App
|
|`--+ models
|   |`-- __init__.py
|   |`-- models.py
|    `-- utils.py
|
 `--+ blueprints
    |`-- __init__.py
    |`-- blueprint_a.py
     `-- blueprint_b.py

And then in App/blueprints/__init__.py you'd import your models and your models helpers. From within blueprint_a.py you'd import the model stuff you'd need and blueprint_b.py you'd import the other model stuff you need there.