From 9d8674d5b64db6ceab2bf331776a8900b8a9a636 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 16 Mar 2013 11:13:07 +0100 Subject: [PATCH] Added more information about app factories. --- docs/patterns/appfactories.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/patterns/appfactories.rst b/docs/patterns/appfactories.rst index 2a6190ea..3ef80b42 100644 --- a/docs/patterns/appfactories.rst +++ b/docs/patterns/appfactories.rst @@ -30,6 +30,9 @@ The idea is to set up the application in a function. Like this:: app = Flask(__name__) app.config.from_pyfile(config_filename) + from yourapplication.model import db + db.init_app(app) + from yourapplication.views.admin import admin from yourapplication.views.frontend import frontend app.register_blueprint(admin) @@ -51,6 +54,21 @@ get access to the application with the config? Use Here we look up the name of a template in the config. +Extension objects are not initially bound to an application. Using +``db.init_app``, the app gets configured for the extension. No +application-specific state is stored on the extension object, so one extension +object can be used for multiple apps. For more information about the design of +extensions refer to :doc:`/extensiondev`. + +Your `model.py` might look like this when using `Flask-SQLAlchemy +`_:: + + from flask.ext.sqlalchemy import SQLAlchemy + # no app object passed! Instead we use use db.init_app in the factory. + db = SQLAlchemy() + + # create some models + Using Applications ------------------