Changed the wording of some sentences there were difficult to understand.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Reetta Vaahtoranta · committed by Reetta Vaahtoranta · parent d4f8634 · Browse files · 4 files·+13 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+13 added−20 removed
- other:+13 added−20 removed
Provenance
- Commit
0d648fa- Tree
3c789c8- Author
Reetta Vaahtoranta <reetta@reetta-Satellite-Pro-C660.(none)>- Committer
Reetta Vaahtoranta <reetta@reetta-Satellite-Pro-C660.(none)>- Parent
d4f8634
4 files changed+13 added−20 removed
modified:docs/tutorial/dbinit.rst+4 added-6 removed
1 unmodified line2 3 Step 4: Creating The Database4 =============================5 6-Flaskr is a database powered application as outlined earlier, and more7-precisely, an application powered by a relational database system. Such6+As outlined earlier, Flaskr is a database powered application, and more7+precisely, it is an application powered by a relational database system. Such8 systems need a schema that tells them how to store that information. So9 before starting the server for the first time it's important to create10 that schema.11 2 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. Also one has19-to provide the path to the database there which leaves some place for20-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 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 database19 for you to the application.20 21 To do this we can create a function called `init_db` that initializes the24-database. Let me show you the code first. Just add that function below22+database. Let me show you the code first. Just add this function below23 the `connect_db` function in `flaskr.py`::24 25 def init_db():26 with app.app_context():41 unmodified linesmodified:docs/tutorial/folders.rst+2 added-2 removed
9 unmodified lines10 /static11 /templates12 13 The `flaskr` folder is not a python package, but just something where we14-drop our files. Directly into this folder we will then put our database15-schema as well as main module in the following steps. The files inside14+drop our files. We will then put our database schema as well as main module15+into this folder. It is done in the following way. The files inside16 the `static` folder are available to users of the application via `HTTP`.17 This is the place where css and javascript files go. Inside the18 `templates` folder Flask will look for `Jinja2`_ templates. The19 templates you create later in the tutorial will go in this directory.4 unmodified linesmodified:docs/tutorial/schema.rst+2 added-4 removed
1 unmodified line2 3 Step 1: Database Schema4 =======================5 6-First we want to create the database schema. For this application only a7-single table is needed and we only want to support SQLite so that is quite8-easy. Just put the following contents into a file named `schema.sql` in9-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:8 9 .. sourcecode:: sql10 11 drop table if exists entries;12 unmodified linesmodified:docs/tutorial/setup.rst+5 added-8 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` inside the `flaskr` folder. For starters we8-will add the imports and create the application object. For small9-applications it's a possibility to drop the configuration directly into10-the module which we will be doing here. However a cleaner solution would11-be to create a separate `.ini` or `.py` file and load that or import the7+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.12 13 First we add the imports in `flaskr.py`::14 49 unmodified lines64 debug flag enables or disables the interactive debugger. *Never leave65 debug mode activated in a production system*, because it will allow users to66 execute code on the server!67 69-We also add a method to easily connect to the database specified. That70-can be used to open a connection on request and also from the interactive71-Python shell or a script. This will come in handy later. We create a68+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.72 33 unmodified lines