10000 A bit of tweaking, added some screenshots · pythonanywhere/flask-tutorials@ef0b5ac · GitHub
[go: up one dir, main page]

Skip to content

Commit ef0b5ac

Browse files
committed
A bit of tweaking, added some screenshots
1 parent ef7ce0f commit ef0b5ac

3 files changed

+21
-13
lines changed

flask-tutorial-login-page-initial.png

6.26 KB
Loading

flask-tutorial-new-console-links.png

15.3 KB
Loading

tutorial-2.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ a page, all of those comments being stored in a database:
99

1010
<img width="500" src="/static/images/flask-tutorial-final-result.png">
1111

12-
It was made up of two files; a Python one which controlled what it did, and a template one that controlled
12+
It was made up of two files; a Python file which controlled what it did, and a template file that controlled
1313
how it was displayed. All of our code was under source-code control, and it was running as a website on
1414
PythonAnywhere.
1515

@@ -26,19 +26,19 @@ IMAGE HERE -- login page
2626
IMAGE HERE -- main page
2727

2828
Adding these new features will require us to do a bit of work in the background; our existing site works
29-
fine for what it is, but it's not very extensible, so we'll fix that as we go. You'll learn about the
30-
Flask-Login extension, database migrations, and virtualenvs -- all very useful stuff :-)
29+
fine for what it is, but it's not very extensible, and we'll fix that as we go. You'll learn about the
30+
Flask-Login extension, database migrations, and virtualenvs -- all very useful stuff.
3131

3232
Let's get started!
3333

3434

35-
## Handling login and logout
35+
## Handling login and logout: the basics
3636

37-
Just like we did before, we'll start off by designing how the site should work. We already have a
37+
Just like we did before, we'll start off by designing how the site should look. We already have a
3838
page that lists all of the comments, and allows people to add new comments. But we don't have a login page,
3939
so let's start by writing one. Log in to PythonAnywhere, then go to the "Files" tab, and then down into the "mysite"
4040
directory that contains your code, and then to the "templates" subdirectory. Enter the filename "login_page.html"
41-
into the "new file" input, then click the "new file button". You'll find yourself in the (hopefully very familiar) editor,
41+
into the "new file" input, then click the "new file" button. You'll find yourself in the (hopefully very familiar) editor,
4242
where you should enter the following HTML template code:
4343

4444
<html>
@@ -88,7 +88,8 @@ where you should enter the following HTML template code:
8888
</body>
8989
</html>
9090

91-
This should be pretty clear, certainly if you're familiar with HTML -- most of it is boilerplate, and the form inside
91+
This should be pretty clear -- like the template from the first part of the tutorial, most of it is boilerplate to make it look similar to the
92+
existing front page, and the form inside
9293
the row (inside the container inside the body)
9394
is a simple login form with username and password fields, each of which has a label, and a "Log in" button to submit the form.
9495
Note that the `type` of the password field is "password" --
@@ -104,29 +105,36 @@ near the top of the page, and select the option to open it in a new browser tab.
104105
def login():
105106
return render_template("login_page.html")
106107

107-
Reload the app the button at the top right of the page -- in case you've forgotten, it looks like this:
108+
Save the file, then reload the website using the button at the top right of the page -- in case you've forgotten, it looks like this:
108109

109-
IMAGE HERE
110+
<img src="/static/images/flask-tutorial-reld-button.png">
110111

111112
Once that's done, go to your site in yet another browser tab -- remember, it's at *yourpythonanywhereusername*`.pythonanywhere.com.
112113
You should now have three tabs open -- the template, the Python code, and your site.
113114

114115
On your site, you'll see what you did before -- the page with the list of comments. So next, edit the URL in the browser's address bar
115116
and add "/login/" to the end. Hit return, and we get the login page:
116117

117-
IMAGE HERE
118+
<img src="/static/images/flask-tutorial-login-page-initial.png">
118119

119120
So far, so good! But if you enter a username and a password into the form, you'll get a "Method not allowed" error:
120121

121-
IMAGE HERE
122+
<img width="500" src="/static/images/flask-tutorial-method-not-allowed.png">
122123

123124
Hopefully that will be
124125
familiar from the first tutorial; our form is sending a `POST` request when the "Log in" button is clicked, and our
125126
view doesn't handle that method yet.
126127

127128
We've reached a state where our site is doing something new, so let's use git to take a checkpoint. In yet another new
128-
browser tab, open up a Bash console from the PythonAnywhere "Consoles" tab. Change your working directory
129-
to `mysite`, which is where all of our code is, by running this command:
129+
browser tab, open up a new Bash console from the PythonAnywhere "Consoles" tab.
130+
131+
<img width="500" src="/static/images/flask-tutorial-new-console-links.png">
132+
133+
(If you're using a free account and you
134+
have two consoles open from going through the tutorial previously, won't be able to open a new one, so you should close
135+
the old ones using the "X"s next to their names, so that you can start with a completely fresh console.)
136+
137+
In the new console, change your working directory to `mysite`, which is where all of our code is, by running this command:
130138

131139
cd mysite
132140

0 commit comments

Comments
 (0)
0