Making Websites with Flask/Creating a web app
Now that you have learned the basics of Flask website development, it is time for the final project. We will be making a web application in which someone can someone can upload their name, age and favourite food, and every other user can view this information.
Creating the homepage
[edit | edit source]We will now create the homepage for the website so that when someone connects, they will know what this is.
Here is the code:
from flask import *
app = Flask(__name__)
#This creates the application object for the site
@app.route('/')
def home():
#You can modify this HTML how you see fit
return """
<!DOCTYPE html>
<html>
<head>
<title>Learn about other users</title>
</head>
<body>
<h1>Welcome to my Web App!</h1>
<a href="/signup">Click here to create a account!</a>
<p style="font-family: sans-serif;">This is a cool website to learn about fellow users.</p>
</body>
</html>
"""
if __name__ == "__main__":
app.run(debug=True)
As you can see, it links to a sign up page, that does not exist yet. We will now address this issue.
Making the sign up page
[edit | edit source]For someone to use your website, they must create an account. But first, we must create a list of all accounts. We will structure it like this: accounts = [{"name": "John Doe", "age": 20, "food": "pizza"}]
. In the next chapter we will code this page, and more.