Skip to content
Myr

Merge pull request #693 from untitaker/factory_docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Added more information about app factories.

authored by Armin Ronacher · committed by Armin Ronacher · parents b9118ca, 9d8674d · Browse files · 1 file+18 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+18 added−0 removed

  • other:+18 added−0 removed

1 file+18 added−0 removed

modified:docs/patterns/appfactories.rst+18 added
28 unmodified lines
29 def create_app(config_filename):30 app = Flask(__name__)31 app.config.from_pyfile(config_filename)3233 from yourapplication.model import db34 db.init_app(app)3536 from yourapplication.views.admin import admin37 from yourapplication.views.frontend import frontend38 app.register_blueprint(admin)39 app.register_blueprint(frontend)
13 unmodified lines
53 return render_template(current_app.config['INDEX_TEMPLATE'])5455Here we look up the name of a template in the config.5657Extension objects are not initially bound to an application. Using58``db.init_app``, the app gets configured for the extension. No59application-specific state is stored on the extension object, so one extension60object can be used for multiple apps. For more information about the design of61extensions refer to :doc:`/extensiondev`.6263Your `model.py` might look like this when using `Flask-SQLAlchemy64<http://pythonhosted.org/Flask-SQLAlchemy/>`_::6566 from flask.ext.sqlalchemy import SQLAlchemy67 # no app object passed! Instead we use use db.init_app in the factory.68 db = SQLAlchemy()6970 # create some models7172Using Applications73------------------7475So to use such an application you then have to create the application
18 unmodified lines