Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Delayed DB Engine initialization (add init_app method) #156

Open
akaRem opened this issue Oct 5, 2014 · 1 comment
Open

Comments

@akaRem
Copy link

akaRem commented Oct 5, 2014

Hi!

I've recently read a book by Miguel Grinberg called Flasky
And found there a very widely used pattern of create_app function, see source

The idea is to create and register all extensions used in app and do not initialize them with concrete config/settings (because lots of things differ for testing/development/production).

The main parts of this pattern is:

a) definition of application

# file: app.py

from flask import Flask
from flask.ext.cool_thing import CoolThing
from config import config  # a set of different configs

cool_thing = CoolThing()  # just created, no app at this point, cool_thing not initialized

def create_app(config_name):
    # create an app
    app = Flask(__name__)
    # setup an app
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    # initialize all extensions
    cool_thing.init_app(app)
    return app

b) running an application with concrete settings

# file: manage.py

from app import create_app, cool_thing
from flask.ext.script import Manager

# create an app depending on envvars
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)

@manager.command
def do_stuff(a, b, c):
    cool_thing.do_some(a, b, c)

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

At the moment interface of flask_peewee does not support delayed initialization

I don't have problems with such implementation.
But I think that if flask_peewee could support this features, than it would be more handy to use by neophytes of Flask.

@narzeja
Copy link

narzeja commented Oct 5, 2014

Sounds like this pull request would solve it: #154
Similar issue: #121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants