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
+4-6Lines changed: 4 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,8 @@
3
3
Step 4: Creating The Database
4
4
=============================
5
5
6
-
Flaskr is a database powered application as outlined earlier, and more
7
-
precisely, an application powered by a relational database system. Such
6
+
As outlined earlier, Flaskr is a database powered application, and more
7
+
precisely, it is an application powered by a relational database system. Such
8
8
systems need a schema that tells them how to store that information. So
9
9
before starting the server for the first time it's important to create
10
10
that schema.
@@ -15,13 +15,11 @@ 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. Also one has
19
-
to provide the path to the database there which leaves some place for
20
-
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 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
21
19
for you to the application.
22
20
23
21
To do this we can create a function called `init_db` that initializes the
24
-
database. Let me show you the code first. Just add that function below
22
+
database. Let me show you the code first. Just add this function below
Copy file name to clipboardExpand all lines: docs/tutorial/schema.rst
+2-4Lines changed: 2 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,8 @@
3
3
Step 1: Database Schema
4
4
=======================
5
5
6
-
First we want to create the database schema. For this application only a
7
-
single table is needed and we only want to support SQLite so that is quite
8
-
easy. Just put the following contents into a file named `schema.sql` in
9
-
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 database schema is quite easy. Just put the following contents into a file named `schema.sql` in the just created `flaskr` folder:
Copy file name to clipboardExpand all lines: docs/tutorial/setup.rst
+5-8Lines changed: 5 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,10 @@ 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` inside the `flaskr` folder. For starters we
8
-
will add the imports and create the application object. For small
9
-
applications it's a possibility to drop the configuration directly into
10
-
the module which we will be doing here. However a cleaner solution would
11
-
be to create a separate `.ini` or `.py` file and load that or import the
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
12
11
values from there.
13
12
14
13
First we add the imports in `flaskr.py`::
@@ -66,9 +65,7 @@ debug flag enables or disables the interactive debugger. *Never leave
66
65
debug mode activated in a production system*, because it will allow users to
67
66
execute code on the server!
68
67
69
-
We also add a method to easily connect to the database specified. That
70
-
can be used to open a connection on request and also from the interactive
71
-
Python shell or a script. This will come in handy later. We create a
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
72
69
simple database connection through SQLite and then tell it to use the
73
70
:class:`sqlite3.Row` object to represent rows. This allows us to treat
74
71
the rows as if they were dictionaries instead of tuples.
0 commit comments