Jivan
Jivan

Reputation: 23068

Using route decorator in a Flask blueprint's submodule

I have a blueprint located in /mybp folder and I want to declare views in different files inside this folder:

/mybp/__init__.py
/mybp/some_views.py
/mybp/some_other_views.py

What is the best way to make possible the use of @mybp.route() decorator in files other than __init__.py?

Upvotes: 0

Views: 690

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121654

You'll have to import the mybp object in your other modules:

from mybp import mybp

or using a relative import reference:

from . import mybp

If you import some_views and some_other_views in __init__, do so after creating the mybp Blueprint instance.

Also see the Circular Imports section in the Larger Applications chapter of the Flask documentation.

Upvotes: 1

Related Questions