Skip to content

Make the package a Flask extention so it can be used with init_app #24

@sergioisidoro

Description

@sergioisidoro

When making modular flask applications, it's common not to immediately provide the app in the constructor, but to pass it later on with the method init_app(app) as we can see in the documentation -- https://flask.palletsprojects.com/en/1.1.x/extensions/

With a bit of changes on the constructor this can become a "proper" flask extension
https://flask.palletsprojects.com/en/1.1.x/extensiondev/

The example of the SQLite extension provides an idea on how this could look like:

    def __init__(self, app=None):
        self.app = app
        if app is not None:
            self.init_app(app)

    def init_app(self, app):
        app.config.setdefault('SQLITE3_DATABASE', ':memory:')
        app.teardown_appcontext(self.teardown)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions