You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorial/dbinit.rst
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,9 @@ Such a schema can be created by piping the `schema.sql` file into the
15
15
sqlite3 /tmp/flaskr.db < schema.sql
16
16
17
17
The downside of this is that it requires the sqlite3 command to be
18
-
installed which is not necessarily the case on every system. This also require that we provide the path to the database which can introduce errors. It's a good idea to add a function that initializes the database
18
+
installed which is not necessarily the case on every system. This also
19
+
require that we provide the path to the database which can introduce
20
+
errors. It's a good idea to add a function that initializes the database
19
21
for you to the application.
20
22
21
23
To do this we can create a function called `init_db` that initializes the
Copy file name to clipboardExpand all lines: docs/tutorial/schema.rst
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,10 @@
3
3
Step 1: Database Schema
4
4
=======================
5
5
6
-
First we want to create the database schema. Only a single table is needed
7
-
for this application and we only want to support SQLite so creating the database schema is quite easy. Just put the following contents into a file named `schema.sql` in the just created `flaskr` folder:
6
+
First we want to create the database schema. Only a single table is needed
7
+
for this application and we only want to support SQLite so creating the
8
+
database schema is quite easy. Just put the following contents into a file
9
+
named `schema.sql` in the just created `flaskr` folder:
Copy file name to clipboardExpand all lines: docs/tutorial/setup.rst
+13-9Lines changed: 13 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,12 @@ Step 2: Application Setup Code
4
4
==============================
5
5
6
6
Now that we have the schema in place we can create the application module.
7
-
Let's call it flaskr.py. We will place this file inside the flask folder.
8
-
We will begin by adding the imports we need and by adding the config section.
9
-
For small applications, it is possible to drop the configuration directly into
10
-
the module, and this is what we will be doing here. However a cleaner solution would be to create a separate `.ini` or `.py` file and load that or import the
11
-
values from there.
7
+
Let's call it flaskr.py. We will place this file inside the flask folder.
8
+
We will begin by adding the imports we need and by adding the config
9
+
section. For small applications, it is possible to drop the configuration
10
+
directly into the module, and this is what we will be doing here. However
11
+
a cleaner solution would be to create a separate `.ini` or `.py` file and
12
+
load that or import the values from there.
12
13
13
14
First we add the imports in `flaskr.py`::
14
15
@@ -65,10 +66,13 @@ debug flag enables or disables the interactive debugger. *Never leave
65
66
debug mode activated in a production system*, because it will allow users to
66
67
execute code on the server!
67
68
68
-
We will also add a method that allows for easily connecting to the specified database. This can be used to open a connection on request and also from the interactive Python shell or a script. This will come in handy later. We create a
69
-
simple database connection through SQLite and then tell it to use the
70
-
:class:`sqlite3.Row` object to represent rows. This allows us to treat
71
-
the rows as if they were dictionaries instead of tuples.
69
+
We will also add a method that allows for easily connecting to the
70
+
specified database. This can be used to open a connection on request and
71
+
also from the interactive Python shell or a script. This will come in
72
+
handy later. We create a simple database connection through SQLite and
73
+
then tell it to use the :class:`sqlite3.Row` object to represent rows.
74
+
This allows us to treat the rows as if they were dictionaries instead of
0 commit comments