Rewrapped lines
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 0d648fa · Browse files · 3 files·+20 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+20 added−12 removed
- other:+20 added−12 removed
Provenance
- Commit
afd3c45- Tree
f1535f5- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
0d648fa
3 files changed+20 added−12 removed
modified:docs/tutorial/dbinit.rst+3 added-1 removed
13 unmodified lines14 15 sqlite3 /tmp/flaskr.db < schema.sql16 17 The downside of this is that it requires the sqlite3 command to be18-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 database18+installed which is not necessarily the case on every system. This also19+require that we provide the path to the database which can introduce20+errors. It's a good idea to add a function that initializes the database21 for you to the application.22 23 To do this we can create a function called `init_db` that initializes the24 database. Let me show you the code first. Just add this function below45 unmodified linesmodified:docs/tutorial/schema.rst+4 added-2 removed
1 unmodified line2 3 Step 1: Database Schema4 =======================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 needed7+for this application and we only want to support SQLite so creating the8+database schema is quite easy. Just put the following contents into a file9+named `schema.sql` in the just created `flaskr` folder:10 11 .. sourcecode:: sql12 13 drop table if exists entries;12 unmodified linesmodified:docs/tutorial/setup.rst+13 added-9 removed
2 unmodified lines3 Step 2: Application Setup Code4 ==============================5 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 the11-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 config9+section. For small applications, it is possible to drop the configuration10+directly into the module, and this is what we will be doing here. However11+a cleaner solution would be to create a separate `.ini` or `.py` file and12+load that or import the values from there.13 14 First we add the imports in `flaskr.py`::15 16 # all the imports48 unmodified lines65 debug flag enables or disables the interactive debugger. *Never leave66 debug mode activated in a production system*, because it will allow users to67 execute code on the server!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 a69-simple database connection through SQLite and then tell it to use the70-:class:`sqlite3.Row` object to represent rows. This allows us to treat71-the rows as if they were dictionaries instead of tuples.69+We will also add a method that allows for easily connecting to the70+specified database. This can be used to open a connection on request and71+also from the interactive Python shell or a script. This will come in72+handy later. We create a simple database connection through SQLite and73+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 of75+tuples.76 77 ::78 79 def connect_db():30 unmodified lines