Update docs/extensiondev.rst
Use `current_app` instead of `self.app`.
This commit is contained in:
parent
823bebf13a
commit
be0b5196bf
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::
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue