forked from orbit-oss/flask
Merge pull request #653 from methane/patch-1
docs/extensiondev: Use `current_app` instead of `self.app`
This commit is contained in:
commit
dfdbc00eaf
1 changed files with 4 additions and 5 deletions
|
|
@ -165,6 +165,7 @@ The Extension Code
|
||||||
Here's the contents of the `flask_sqlite3.py` for copy/paste::
|
Here's the contents of the `flask_sqlite3.py` for copy/paste::
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
# Find the stack on which we want to store the database connection.
|
# 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,
|
# 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):
|
class SQLite3(object):
|
||||||
|
|
||||||
def __init__(self, app=None):
|
def __init__(self, app=None):
|
||||||
|
self.app = app
|
||||||
if app is not None:
|
if app is not None:
|
||||||
self.app = app
|
self.init_app(app)
|
||||||
self.init_app(self.app)
|
|
||||||
else:
|
|
||||||
self.app = None
|
|
||||||
|
|
||||||
def init_app(self, app):
|
def init_app(self, app):
|
||||||
app.config.setdefault('SQLITE3_DATABASE', ':memory:')
|
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)
|
app.teardown_request(self.teardown)
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
return sqlite3.connect(self.app.config['SQLITE3_DATABASE'])
|
return sqlite3.connect(current_app.config['SQLITE3_DATABASE'])
|
||||||
|
|
||||||
def teardown(self, exception):
|
def teardown(self, exception):
|
||||||
ctx = stack.top
|
ctx = stack.top
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue