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: en/step_6.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,10 @@
2
2
3
3
Websites like Facebook, YouTube and BBC News have dynamic content: these websites show different content within the same template.
4
4
5
-
Now you will create a new route on your website so that when you go to `http://127.0.0.1/hello/name`, the page will show you a personal greeting. So for example, `/hello/Dana/` displays 'Hello Dana!'.
6
-
5
+
Now you will create a new route on your website so that the page will show you a personalised greeting.
7
6
--- task ---
8
7
9
-
Add a new route to your application:
8
+
Open `app.py` and add a new route to your application:
10
9
11
10
--- code ---
12
11
---
@@ -28,7 +27,7 @@ def hello(name):
28
27
29
28
--- task ---
30
29
31
-
Create a new HTML template called `page.html`, and add the following HTML code to it:
30
+
Create a new HTML template in the templates folder called `page.html`, and add the following HTML code to it:
32
31
33
32
--- code ---
34
33
---
@@ -64,7 +63,7 @@ Open your `index.html` template and add a link to the hello page under the headi
64
63
language: html
65
64
line_numbers: true
66
65
line_number_start: 6
67
-
line_higlights: 7
66
+
line_highlights: 7
68
67
---
69
68
<h1>My website</h1>
70
69
<ahref="/hello/paul">Hi Paul</a>
@@ -85,7 +84,7 @@ Save the changes to `index.html`, and then open `localhost:5000` to see the upda
85
84
title: How does this route work?
86
85
---
87
86
88
-
-`@app.route('/hello/<name>')`: the `<name>` part means it passes the name into the `hello` function as a variable called `name`.
87
+
-`@app.route('/hello/<name>')`: the `<name>` part passes the text written in the URL into the `hello` function as a variable called `name`.
89
88
-`def hello(name)`: this is the function that determines what content is shown. Here, the function takes the given name as a parameter.
90
89
-`return render_template('page.html', name=name)`: this code looks up the template `page.html` and passes in the variable `name` from the URL so that the template can use it.
91
90
@@ -96,8 +95,8 @@ Flask uses `jinja`, a Python library for rendering templates. Look at this code
96
95
<h1>Hello {{ name }}!</h1>
97
96
```
98
97
99
-
This code tells the template to render the variable `name` that was passed in the route function `hello`.
98
+
This code tells the template to use the variable `name` that was passed in the route function `hello`.
100
99
101
-
Visiting `127.0.0.1:5000/hello/` without a name creates an error. Try to think of a way to prevent this error.
100
+
Visiting `localhost:5000/hello/` without a name creates an error.
0 commit comments