wong2
wong2

Reputation: 35720

Flask use the same blueprint across files

this is my project structure:

- app.py
- views/
    - admin/
        - __init__.py
        - note.py
        - album.py

in views/admin/__init__.py I created a blueprint:

admin_bp = Blueprint('admin_bp', __name__, url_prefix='/admin')

and I'd like to use this blueprint in both note.py and album.py

what I've tried:

# note.py

from views.admin import admin_bp

@admin_bp.route('/note/list')
def list_notes():
    pass

But it seems that the url rule is not generated at all

thanks.

Upvotes: 1

Views: 613

Answers (1)

Joe Doherty
Joe Doherty

Reputation: 3948

Are you loading the blueprint in app.py?

from admin import admin_bp
app.register_blueprint(admin_bp)

Ensure that you are importing note.py & album.py inside admin/__init__.py.

This should then load the URLs.

If that fails it may be worth printing the contents of the URL map:

print app.url_map

Regards

Upvotes: 2

Related Questions