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: flask/part3_templates/README.md
+13-6Lines changed: 13 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -169,9 +169,9 @@ Now you'll see how to write 100 web pages with no actual HTML files. Well, excep
169
169
170
170
We are building on the [ex2-app](ex2-app) example app, discussed above.
171
171
172
-
Now, in the third version — the [ex3-app](ex3-app) example app — we will make our two templates much more useful by enabling them to use data read from a separate file, *data.py*. That file contains information (name, ID, address, etc.) about 100 students (not real people).
172
+
Now, in the third version — the [ex3-app](ex3-app) example app — we will make our two templates much more useful by enabling them to use data from a separate file, *data.py*. That file contains a bunch of information (name, ID, address, etc.) about 100 students (not real people).
173
173
174
-
Instead of working with the whole file while working out the bugs, the *students3.py* file uses just two records from the dataset. In addition to the list named DATA, two new functions have been added. These functions are outside the routes, but they are called *in* the routes.
174
+
Instead of working with the whole file while working out the bugs, the *students3.py* file uses just two records from the dataset. In addition to the **list** named `DATA`, two new functions have been added. These functions are outside the routes, but they are called *in* the routes.
175
175
176
176
```
177
177
get_all_students() --> used in index()
@@ -183,17 +183,24 @@ gets the following details about ONE student: name, address, photo
183
183
184
184
* We still have only two routes in our Flask app.
185
185
* We still have only two templates, plus the base template.
186
-
* We have added data about two students in *students3.py*.
186
+
* We have **added** data about two students in *students3.py*.
187
187
* We have added two new Python functions (no Flask code in these):
188
-
* get_all_students()
189
-
* get_student()
188
+
*`get_all_students()`
189
+
*`get_student()`
190
190
191
-
The goal is to provide a list of all students (last names only) with an `<a href="">` that contains the student's ID number. When we click any student's name, a new URL opens, showing us details and a photo for just that one student.
191
+
The goal is to provide a list of all students (last names only), each with an `<a href="">` that contains the student's ID number.
192
+
193
+
1. When we click any student's name, we send a new URL to the browser.
194
+
2. In the Flask app, that URL runs the route decorater: `@app.route('/student/<idnum>')`
195
+
2. That causes the Flask route function `student(idnum)` to run.
196
+
3. That function gets the name, photo, and address for the specific student with that ID number in `DATA`— a Python list of dictionaries you can see in lines 8-11 in [students3.py](ex3-app/students3.py).
192
197
193
198
The ID number is used in the link because it is sure to be unique, unlike a name. We have been using a number in the route `@app.route('/student/<idnum>')` all along.
194
199
195
200
The complete code for this app is in the folder [ex3-app](ex3-app).
196
201
202
+
**The complete dataset of 100 students** is used in in [students4.py](ex3-app/students4.py).
203
+
197
204
**To run the final, complete app** in your activated virtualenv, `cd` into the `ex3-app` directory and type this at the bash prompt (`$`) in Terminal:
0 commit comments