Browse files

Added more information about app factories.

  • Loading branch information...
untitaker committed Mar 16, 2013
1 parent b9118ca commit 9d8674d5b64db6ceab2bf331776a8900b8a9a636
Showing with 18 additions and 0 deletions.
  1. +18 −0 docs/patterns/appfactories.rst
@@ -30,6 +30,9 @@ The idea is to set up the application in a function. Like this::
app = Flask(__name__)
+ from yourapplication.model import db
+ db.init_app(app)
from yourapplication.views.admin import admin
from yourapplication.views.frontend import frontend
@@ -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 `` 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

0 comments on commit 9d8674d

Please sign in to comment.