update the tutorial database doc code so it works
This commit is contained in:
parent
089f6a1c50
commit
ea709bb58f
1 changed files with 3 additions and 1 deletions
|
|
@ -41,7 +41,6 @@ response is sent.
|
||||||
import click
|
import click
|
||||||
from flask import current_app, g
|
from flask import current_app, g
|
||||||
|
|
||||||
|
|
||||||
def get_db():
|
def get_db():
|
||||||
if 'db' not in g:
|
if 'db' not in g:
|
||||||
g.db = sqlite3.connect(
|
g.db = sqlite3.connect(
|
||||||
|
|
@ -119,6 +118,8 @@ Add the Python functions that will run these SQL commands to the
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:caption: ``flaskr/db.py``
|
:caption: ``flaskr/db.py``
|
||||||
|
|
||||||
|
from flask.cli import with_appcontext
|
||||||
|
|
||||||
def init_db():
|
def init_db():
|
||||||
db = get_db()
|
db = get_db()
|
||||||
|
|
||||||
|
|
@ -127,6 +128,7 @@ Add the Python functions that will run these SQL commands to the
|
||||||
|
|
||||||
|
|
||||||
@click.command('init-db')
|
@click.command('init-db')
|
||||||
|
@with_appcontext
|
||||||
def init_db_command():
|
def init_db_command():
|
||||||
"""Clear the existing data and create new tables."""
|
"""Clear the existing data and create new tables."""
|
||||||
init_db()
|
init_db()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue