Skip to main content

Auto register all project flask-blueprints.

Project description

Upload Python Package Python application

Flask Blueprint autoinclude

A function to automatically register all flask-blueprints from a project.
register_blueprints from flask_bp_autoregister.blueprints


When using flask blueprints then after defining them you have to register them all this can possible look like this.

# in some config.py or __init__.py
def register_my_blueprints(used_flask_app: any):
    from my_app.views import home_views
    from my_app.views import package_views
    from my_app.views import account_views

    used_flask_app.register_blueprint(home_views.app_bp)
    used_flask_app.register_blueprint(package_views.app_bp)
    used_flask_app.register_blueprint(account_views.app_bp) 

# and then in your run.py or similar

from my_app import flask_app
from my_app import register_my_blueprints

register_my_blueprints(flask_app)

if __name__ == '__main__':
    flask_app.run()

The register_blueprints code can get really long and you always have to remember where your blueprints are.


For this is had created a function register_blueprints which automatically will search for all blueprints in your project and register them.

from my_app import flask_app
from flask_bp_autoregister.blueprints import register_blueprints


register_blueprints(flask_app, 'my_project/src/my_app')


if __name__ == '__main__':
    flask_app.run()

The path attribute is not really needed you can also use it without then all blueprints inside of the project will be registered automatically

from my_app import flask_app
from flask_bp_autoregister.blueprints import register_blueprints


register_blueprints(flask_app)


if __name__ == '__main__':
    flask_app.run()

When you have some commented Blueprints inside of your project, register_blueprints will try to register them too
which will raise an AttributeError you can disable this with silent=True

from my_app import flask_app
from flask_bp_autoregister.blueprints import register_blueprints


register_blueprints(flask_app, silent=True) # will prevent raising AttributeError


if __name__ == '__main__':
    flask_app.run()

Tested for Versions

  • 3.6, 3.7, 3.8

Installing

Versioning

  • For the versions available, see the tags on this repository.

Authors

  • Felix Eisenmenger - Initial work

License

  • This project is licensed under the MIT License - see the LICENSE.md file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autoinclude_blueprints-1.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

autoinclude_blueprints-1.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file autoinclude_blueprints-1.0.1.tar.gz.

File metadata

  • Download URL: autoinclude_blueprints-1.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for autoinclude_blueprints-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8c8475478aee32d1ed25984fe0a25a7a6643a65d996f8c610bd1d891ca32a3d8
MD5 e9c56992988f1323afd89c985cedcbaa
BLAKE2b-256 924b53ce84dddb9c93756d123297dcd0682571fbf7ede0ef47494e9a361a497d

See more details on using hashes here.

File details

Details for the file autoinclude_blueprints-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: autoinclude_blueprints-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for autoinclude_blueprints-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2fdf3329f52f22ca44cb89ef0197669fc6d61f52fec017ecd422e774eb5f4250
MD5 42e65c61935e712b62a20c81eab3918e
BLAKE2b-256 5d2400a141b001f8a8aef91fdea8e45026fc2e981e8bfc4f8e3dd3f2d602d038

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page