Commits

Naoki INADA committed be0b519

Update docs/extensiondev.rst

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

  • Participants
  • Parent commits 823bebf

Comments (0)

Files changed (1)

File docs/extensiondev.rst

 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,
     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:')
                 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