Skip to content

Commit 2db912a

Browse files
authored
copy edits
1 parent a27b42b commit 2db912a

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

en/step_7.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
## Adding dynamic content
1+
## Add dynamic content
22

3-
So far you've learned to deliver static HTML web pages using templates. Lets add some dynamic content to the pages to display different information. Large websites like Facebook, YouTube and BBC News show different content depending on the page you visit, even though the templates are very similar.
3+
Now you know how to deliver static HTML web pages using templates. Large websites like Facebook, YouTube and BBC News have dynamic content: these websites show different content depending on the page you visit, even though the templates are very similar.
44

5-
Now you'll create a new route on your website so that when you go to `http://127.0.0.1/hello/name`, it will say "Hello name!" and replace 'name' with whatever you put there; so `/hello/Paul/` will display "Hello Paul!".
5+
You will now add some dynamic content to your pages so they can display different information.
6+
7+
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 says 'Hello name!', replacing 'name' with whatever you put there. So for example, `/hello/Dana/` displays 'Hello Dana!'.
68

79
--- task ---
810

9-
Create a new route in your application like so:
11+
Add the following code to create a new route in your application:
1012

1113
```python
1214
@app.route('/hello/<name>')
1315
def hello(name):
1416
return render_template('page.html', name=name)
1517
```
1618

17-
- `@app.route('/hello/<name>')` - the `<name>` part means it passes the name into the `hello` function as a variable called `name`
18-
- `def hello(name)` - this is the function that determines what content is shown - this time it takes the given name as a parameter
19-
- `return render_template('page.html', name=name)` - here we look up the template `page.html` and pass in the variable `name` from the URL, so the template can use it
19+
- `@app.route('/hello/<name>')`: the `<name>` part means it passes the name into the `hello` function as a variable called `name`.
20+
- `def hello(name)`: this is the function that determines what content is shown. Here, the function takes the given name as a parameter.
21+
- `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.
2022

2123
--- /task ---
2224

@@ -36,11 +38,11 @@ Create a new HTML template called `page.html`, and add the following HTML code t
3638

3739
--- task ---
3840

39-
Save the files and visit `http://127.0.0.1:5000/hello/paul`. It should look like this:
41+
Save the files and visit `http://127.0.0.1:5000/hello/paul`. The page you see should look like this:
4042

4143
![Hello Paul!](images/flask-hello-paul.png)
4244

43-
Try it with different names!
45+
Try `http://127.0.0.1/hello/name` with different names!
4446

4547
--- /task ---
4648

@@ -50,23 +52,23 @@ Try it with different names!
5052
title: What's happening here?
5153
---
5254

53-
Flask uses `jinja`, a Python library for rendering templates. Using the braces (curly brackets) on this line:
55+
Flask uses `jinja`, a Python library for rendering templates. Look at this code with the braces (curly brackets):
5456

5557
```html
5658
<h1>Hello {{ name }}!</h1>
5759
```
5860

59-
... tells the template to render the variable `name` which was passed in the route function `hello`.
61+
This code tells the template to render the variable `name` that was passed in the route function `hello`.
6062

61-
Visiting `127.0.0.1:5000/hello/` without a name will create an error. Think about how you can prevent this from happening.
63+
Visiting `127.0.0.1:5000/hello/` without a name creates an error. Try to think of a way to prevent this error.
6264

6365
--- /collapse ---
6466

6567
--- task ---
6668

67-
Create a link to your new dynamic hello page from your index.
69+
Create a link to your new, dynamic hello page from your index.
6870

69-
Edit `index.html` to add a link to your new hello page under the heading.
71+
Edit `index.html` to add a link to the hello page under the heading.
7072

7173
```html
7274
<h1>My website</h1>
@@ -77,7 +79,7 @@ Edit `index.html` to add a link to your new hello page under the heading.
7779

7880
--- task ---
7981

80-
Save your changes and refresh the index page to see the result.
82+
Save the changes to `index.html`, and then refresh the index page in the browser to see the updated version.
8183

8284
![flask app link](images/flask-app-link.png)
8385

0 commit comments

Comments
 (0)