Skip to content
Myr

Update docs/extensiondev.rst

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

Use `current_app` instead of `self.app`.

authored by INADA Naoki · committed by INADA Naoki · parent 823bebf · Browse files · 1 file+4 added−5 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+4 added−5 removed

  • other:+4 added−5 removed

1 file+4 added−5 removed

modified:docs/extensiondev.rst+4 added-5 removed
163 unmodified lines
164165Here's the contents of the `flask_sqlite3.py` for copy/paste::166167 import sqlite3168 from flask import current_app169170 # Find the stack on which we want to store the database connection.171 # Starting with Flask 0.9, the _app_ctx_stack is the correct one,172 # before that we need to use the _request_ctx_stack.
5 unmodified lines
178179 class SQLite3(object):180181 def __init__(self, app=None):182 self.app = app183 if app is not None:182 self.app = app183 self.init_app(self.app)184 self.init_app(app)184 else:185 self.app = None185186 def init_app(self, app):187 app.config.setdefault('SQLITE3_DATABASE', ':memory:')188 # Use the newstyle teardown_appcontext if it's available,
3 unmodified lines
192 else:193 app.teardown_request(self.teardown)194195 def connect(self):197 return sqlite3.connect(self.app.config['SQLITE3_DATABASE'])196 return sqlite3.connect(current_app.config['SQLITE3_DATABASE'])197198 def teardown(self, exception):199 ctx = stack.top200 if hasattr(ctx, 'sqlite3_db'):
220 unmodified lines