diff --git a/docs/extensiondev.rst b/docs/extensiondev.rst index d266e1a2..0615e4db 100644 --- a/docs/extensiondev.rst +++ b/docs/extensiondev.rst @@ -165,6 +165,7 @@ The Extension Code Here's the contents of the `flask_sqlite3.py` for copy/paste:: import sqlite3 + from flask import current_app # Find the stack on which we want to store the database connection. # Starting with Flask 0.9, the _app_ctx_stack is the correct one, @@ -178,11 +179,9 @@ Here's the contents of the `flask_sqlite3.py` for copy/paste:: class SQLite3(object): def __init__(self, app=None): + self.app = app if app is not None: - self.app = app - self.init_app(self.app) - else: - self.app = None + self.init_app(app) def init_app(self, app): app.config.setdefault('SQLITE3_DATABASE', ':memory:') @@ -194,7 +193,7 @@ Here's the contents of the `flask_sqlite3.py` for copy/paste:: app.teardown_request(self.teardown) def connect(self): - return sqlite3.connect(self.app.config['SQLITE3_DATABASE']) + return sqlite3.connect(current_app.config['SQLITE3_DATABASE']) def teardown(self, exception): ctx = stack.top