diff --git a/docs/tutorial/database.rst b/docs/tutorial/database.rst index 934f6008..c4104b8a 100644 --- a/docs/tutorial/database.rst +++ b/docs/tutorial/database.rst @@ -41,7 +41,6 @@ response is sent. import click from flask import current_app, g - def get_db(): if 'db' not in g: g.db = sqlite3.connect( @@ -119,6 +118,8 @@ Add the Python functions that will run these SQL commands to the .. code-block:: python :caption: ``flaskr/db.py`` + from flask.cli import with_appcontext + def init_db(): db = get_db() @@ -127,6 +128,7 @@ Add the Python functions that will run these SQL commands to the @click.command('init-db') + @with_appcontext def init_db_command(): """Clear the existing data and create new tables.""" init_db()