Import and register all Flask Blueprints (including nested) from a package directory.
Project description
Flask Blueprint Autoimporter
flask-blueprints
will import and register all nested Flask Blueprints under a given package directory.
Synopsis
Register all Flask Blueprints (including nested) from a package directory.
Usage
Create an empty package app.blueprints
and register your blueprints:
from flask import Flask
from flask_blueprints import register_blueprints
app = Flask(__name__)
register_blueprints(app, 'app.blueprints')
Blueprints can now be placed under this package, as such:
.
└── app
├── blueprints
│ ├── account
│ │ ├── account.py
│ │ ├── contact
│ │ │ ├── contact.py
│ │ │ └── __init__.py
│ │ └── __init__.py
│ ├── api
│ │ ├── account
│ │ │ ├── account.py
│ │ │ ├── contact
│ │ │ │ ├── contact.py
│ │ │ │ └── __init__.py
│ │ │ └── __init__.py
│ │ ├── __init__.py
│ │ └── user
│ │ ├── __init__.py
│ │ └── tribute.py
│ ├── __init__.py
│ └── project
│ ├── documents.py
│ ├── __init__.py
│ ├── project.py
│ └── search.py
└── __init__.py
Blueprint __init__.py
files should look something like the following:
from flask import Blueprint
bp = Blueprint('project', __name__)
from . import documents
from . import project
from . import search
(Note that the top-level app/blueprints/__init__.py
is not a blueprint
package, and therefore should not have a blueprint defined.)
The blueprint files themselves can then define the routes. For example:
from flask import redirect, url_for
from . import bp
@bp.post('/project/<int:project_id>/store')
def store(project_id):
# ...
return redirect(url_for('project.show', project_id=project_id))
If the blueprint variable is not bp
, then this can be customised:
register_blueprints(app, 'app.blueprints', bp='bp')
Further Reading
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_blueprints-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b9b4e8e3c173dcf807245284442838fc6e8c113c85adaab9457af9750dfda2a |
|
MD5 | 32a5615d4c07ca8bb477b71c6496efd5 |
|
BLAKE2b-256 | 1fab443f65632b49107c753d846e9dcd141f63e5a98f1b624bec619e4eaf06ee |