You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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()
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.
The text was updated successfully, but these errors were encountered:
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 sourceThe 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
b) running an application with concrete settings
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.The text was updated successfully, but these errors were encountered: