In this lab, you will learn about taking and processing information, given by a user via HTML forms!
Before we start, make sure to fork the repo and clone the code.
As you can see, in the code we provided, you have a ready app.py (Flask app), login.html, home.html and `home.html files, these will be the files you will edit this lab. Explore the project files to have a better understanding of what's going on, even try to run the app!
It should look something like this:

First things first, in the top of app.py, you have some variables configured. Feel free to edit them according to your own preferences. The variables looks something like this:
username = "llo2ay"
password = "123"
facebook_friends=["Loai","Yonathan","Adan", "George", "Fouad", "Celina"]-
Editing the
loginroute inapp.py, and the login form inlogin.html. It should:- Take input in the form, and process it in
loginroute. - You should check if it's a
POSTrequest:- If it is, check for credentials. (if the username and password from
login.htmlmatch theusernameandpasswordvariables) - If they match, you should proceed to
home.html. - Make sure to update the
<form>attributes (method and action) accordingly.
- If it is, check for credentials. (if the username and password from
- If it's a
GETrequest. you should stay on thelogin.htmlpage to try again.- Remember:
GETis the default method.
- Remember:
- Take input in the form, and process it in
-
Create/Define a new route in
app.pyand call ithome.- You should link
homeroute tohome.html. - Make sure to replace
render_template('home.html')withredirect(url_for('home'))in theloginroute. - Checkpoint! Test out your website, make sure it works properly.
- You should link
-
Using
facebook_friendslist, pass it tohome.htmlusing thehomefunction/route inapp.py.- Replace the current "friends" in the page with a
for loopthat loops through this list. - Costumize/Edit
facebook_friendslist and add your classmates/family members. - Run your app. Show your friends/family members.
- Replace the current "friends" in the page with a
-
Now, let's add a variable route called
friend_existswith name as an input:- You should create a new route, called
/friend_existsthat additionally takes a variable in the route called name, for example - /friends_exists/Fouad. - The route should render
friend_exists.html. - Make sure that this route accepts
GETandPOSTas methods. - Add a link to each "friend" in
home.html(facebook_friendslist). - Make the link the route
friend_existsand the name of the friend. - The function checks if the name is in the
facebook_friendsand displays True or False according to the results in 'friend_exists.html`.
- You should create a new route, called
If you have extra time, continue to the Bonus Problems below.
If not, make sure your code is saved in Repl.it!
-
When you login, is the username case sensitive? If not, fix these issues so your app could work properly.
-
Add a dictionary of usernames and passwords, accounts that are allowed to log in to your Facebook app.
-
Instead of
friend_exists/{{name}}, make the link to each "friend" inhome.html(facebook_friendslist), that when clicked, it should Google the name.
- In other words, if you click on
"Loai", it should take you to the results google page when searching for "Loai".
- If you have extra time, complete yesterday's (or any other) lab(s) if you haven't yet!