Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 7f30cf9

Browse files
committed
A little copy editing, paragraph to mention visiting /emails.html
1 parent d069c60 commit 7f30cf9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

core/data.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Outside of Python, dictionaries are often called ``hash tables``, ``hash maps``
131131

132132
At the moment we don't have any way to store email addresses. But if we add a list to our website then we can keep them temporarily. Sure it will only stay around until the web server stops, but it is a good start.
133133

134-
Let's add a list to the top of the Python code, just after all the `import` lines and `app = Flask(__name__)`:
134+
Let's add an empty list to the top of the Python code, just after all the `import` lines and `app = Flask(__name__)`:
135135

136136
email_addresses = []
137137

@@ -141,26 +141,26 @@ Now in our `signup()` function we can add the email address instead of printing
141141
def signup():
142142
email = request.form['email']
143143
email_addresses.append(email)
144-
print(email_addresses)
144+
print(email_addresses)
145145
return redirect('/')
146146

147-
Check the output you get when submitting a form. It prints out the entire list every time.
147+
Check the output you get in the console, when submitting a form. It prints out the entire list every time.
148148

149149
## Listing email addresses
150150

151-
Printing out our email addresses to the console is a bit of a hassle. If you wanted to read the list then you have to open the terminal and scan through for the printout. It would be so much easier to have a web page that lists all the email addresses that we have collected.
151+
Just printing out our email addresses is a bit of a hassle. If you wanted to read the list then you have to open the terminal and scan through for the printout. It would be so much easier to have a web page that lists all the email addresses that we have collected.
152152

153-
We know how to create a new page in Flask, it's just a function. And we can pass the list of emails directly to our HTML template like so:
153+
We know how to create a new page in Flask, it's just a function. And we can pass the list of emails directly to a HTML template like so:
154154

155155
@app.route('/emails.html')
156156
def emails():
157-
return render_template('emails.html', email_addresses = email_addresses)
157+
return render_template('emails.html', email_addresses=email_addresses)
158158

159-
Here the `render_template()` function takes the name of the template (`'emails.html'`) and extra data to be used when rendering the page. We wrote `email_addresses = email_addresses` to say that our variable `email_addresses` will be available in the template using the same name.
159+
Here the `render_template()` function takes the name of the template (`'emails.html'`) and extra data to be used when rendering the page. We wrote `email_addresses=email_addresses` to say that our variable `email_addresses` will be available in the template using the same name.
160160

161161
Now we need our HTML template. In our previous template we didn't actually do anything but plain HTML. But now we need to print the list of email addresses, so we'll use a `for` loop in the template.
162162

163-
Here is the content of `emails.html` for the _templates_ directory:
163+
Here is an example of the content of `emails.html` for the _templates_ directory:
164164

165165
{% raw %}
166166

@@ -182,7 +182,9 @@ Here is the content of `emails.html` for the _templates_ directory:
182182

183183
{% endraw %}
184184

185-
Check out the _for_ loop that we use in the template. It is similar to the one used in Python but subtly different. You can see it doesn't contain the `:` at the end of the first line, and it needs an `endfor` statement to end the loop.
185+
Check out the _for_ loop that we use in the template. It is similar to the one used in Python but subtly different. You can see it doesn't contain the `:` at the end of the first line, and it needs an `endfor` statement to end the loop. This comes from the template making use of flask's Jinja2 templating language, that's designed to be very simple to read and write.
186+
187+
Now you can **reboot your server, submit some emails, and visit [/emails.html](http://127.0.0.1:5000/emails.html)** to check everything is working as expected! What happens if you restart the server again?
186188

187189
## Success!
188190

0 commit comments

Comments
 (0)