Welcome to Level Two, young coder! ๐ You have mastered the basics of Python โ variables, loops, functions, OOP, file handling, and even APIs. Now, it is time to take your skills to the next level by building web applications.
Have you ever wondered how websites like Jumia, Instagram, or your favourite blog work? They are all built using web technologies. In this module, you will learn how to build your own web applications using Flask, a lightweight Python web framework that is perfect for beginners.
Think of Flask as a magical bridge ๐ between your Python code and the web. It handles all the complex parts of web communication so you can focus on building cool features. By the end of this module, you will have built your very own web application that you can share with friends and family!
Let us begin this exciting journey into web development! ๐
By the end of this module, you will be able to:
Ada loved to learn new things. She had just finished Python Level One and was eager to build something her friends could actually use. She thought, "My friends always ask me to help them with their homework. I wish I had a website where they could just enter their questions and get answers!"
Her mentor, Mr. Obi, said, "Ada, that is a fantastic idea! You can build a web application using Flask. It is a Python framework that makes web development easy. Let us start simple โ build a greeting app where users enter their name and get a personalized welcome message."
Ada was excited. She set up Flask on her computer, created a route for the home page, and added a form where users could type their names. She learned how to render HTML templates and pass data to them. She even added some CSS to make it look beautiful.
"Now my friends can visit my website and get a greeting anytime!" Ada said. She shared the link with her friends, and they loved it. Ada had built her first web application. And now, you will build yours too! ๐
Definition: A web framework is a collection of tools and libraries that helps you build web applications more easily.
Why it is important: Building a web application from scratch is very complex. A web framework handles the common tasks โ like routing, handling requests, and managing sessions โ so you can focus on what makes your app special.
Simple explanation: Imagine you are building a house. Instead of cutting down trees and making your own bricks, you buy pre-made materials from a shop. A web framework is like those materials โ it gives you the building blocks you need.
Real-life example: Flask and Django are popular Python web frameworks. React and Angular are popular front-end frameworks.
School example: Your teacher gives you a template for your project report so you only have to fill in your content.
Home example: You use a recipe book instead of inventing your own recipes from scratch.
Nigerian example: A developer in Lagos uses Flask to build a website for a local business instead of writing everything from scratch.
Illustration:
WEB FRAMEWORK CONCEPT
+-------------------------------------------------+
| Your Python code โ Flask โ Web application |
| (You write routes, (Flask handles |
| templates, etc.) HTTP requests, |
| templating, etc.) |
+-------------------------------------------------+
Mini summary: A web framework simplifies web development by providing common tools and structures.
Definition: Flask is a lightweight web framework for Python that is easy to learn and use. It is great for small to medium-sized applications.
Why it is important: Flask gives you the power to build web apps quickly without a lot of complicated code. It is perfect for beginners and prototypes.
Simple explanation: Think of Flask as a tiny, friendly robot ๐ค that helps you turn your Python functions into web pages. You tell it what to do, and it handles all the web stuff for you.
Real-life example: Flask is used by companies like Netflix, Airbnb, and Uber for certain services.
School example: You use a simple calculator instead of doing complex math by hand โ Flask is similarly simple.
Home example: A small toolkit for fixing things around the house โ Flask gives you essential tools without extra weight.
Nigerian example: A startup in Abuja uses Flask to build its MVP (Minimum Viable Product) quickly and cheaply.
Illustration:
FLASK IS LIGHTWEIGHT
+-------------------------------------------------+
| Flask is: |
| - Easy to learn |
| - Flexible |
| - Perfect for beginners |
| - Used in many real-world projects |
| - No complicated setup required |
+-------------------------------------------------+
Mini summary: Flask is a lightweight, beginner-friendly web framework for Python. It gives you essential tools without extra complexity.
Definition: To use Flask, you need to install it and set up a project structure. This ensures your project runs correctly and is easy to manage.
Why it is important: Just like you need a kitchen to cook, you need a Python environment with Flask installed to build web apps. A virtual environment keeps your project's dependencies isolated.
Simple explanation: Imagine you are an artist. You need your own studio with all your paints and brushes organized. A virtual environment is like your studio โ it keeps everything for that project separate from your other projects.
Steps to set up:
python -m venv venvvenv\Scripts\activatesource venv/bin/activatepip install flaskapp.pyReal-life example: A chef organizes their kitchen before cooking โ ingredients, utensils, and tools all in their place.
School example: You organize your notebooks by subject before studying.
Home example: You set up your workspace before starting a project.
Nigerian example: A developer in Enugu sets up a virtual environment for each client project.
Illustration:
FLASK SETUP STEPS
+-------------------------------------------------+
| mkdir my_flask_app |
| cd my_flask_app |
| python -m venv venv |
| source venv/bin/activate (or venv\Scripts\activate) |
| pip install flask |
| touch app.py |
+-------------------------------------------------+
Mini summary: Set up a virtual environment, install
Flask, and create your app.py file to start developing.
Definition: A Flask application is a Python script that defines routes and handles HTTP requests. The simplest app returns a "Hello, World!" message.
Why it is important: This is the "Hello, World!" of web development โ it proves everything works and gives you a starting point.
Simple explanation: You write a function that returns a greeting, and Flask turns it into a web page that anyone can visit.
Code:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug=True)
To run it:
app.py.python app.py.http://127.0.0.1:5000.Real-life example: A restaurant menu โ the route is like a dish name, and the function is the recipe.
School example: Your teacher says "Good morning" when you enter class โ that is the response.
Home example: Your doorbell rings and you say "Hello!"
Nigerian example: A greeting app that says "Welcome" in Yoruba, Igbo, or Hausa.
Illustration:
FIRST FLASK APP
+-------------------------------------------------+
| Browser โ http://127.0.0.1:5000/ |
| โ |
| Flask matches route '/' to home() |
| โ |
| home() returns "Hello, World!" |
| โ |
| Browser displays "Hello, World!" |
+-------------------------------------------------+
Mini summary: The basic Flask app has a route for the home page and returns a simple greeting. Run it and see it in your browser!
Definition: A route is a URL pattern
(e.g., /about). A view function is the
function that runs when that URL is visited.
Why it is important: Routes define the pages of your website. Each page needs its own route and view function.
Simple explanation: Think of a restaurant menu. Each dish (route) has a recipe (view function) that tells the kitchen how to make it. When a customer orders a dish (visits a URL), the kitchen follows the recipe (view function runs).
How to add multiple routes:
@app.route('/')
def home():
return "Home Page"
@app.route('/about')
def about():
return "About Page"
@app.route('/user/<name>')
def user(name):
return f"Hello, {name}!"
Real-life example: A website with pages for Home, About, Contact, and Products.
School example: Your school has different rooms for different subjects โ each room is a route.
Home example: Different rooms in your house (kitchen, bedroom, living room).
Nigerian example: A local business website with pages for Services, Prices, Testimonials, and Contact.
Illustration:
ROUTES AND VIEW FUNCTIONS
+-------------------------------------------------+
| Route: / โ home() โ "Home Page" |
| Route: /about โ about() โ "About Page" |
| Route: /user/Ada โ user("Ada") โ "Hello, Ada!" |
+-------------------------------------------------+
Mini summary: Routes define URLs, and view functions generate the content for those URLs. Each route is like a page in your website.
Definition: Jinja2 is a templating engine used by Flask. It allows you to write HTML files with dynamic content that can be filled in by Python.
Why it is important: Instead of returning raw strings, you can return beautiful HTML pages. Templates separate design from logic, making your code cleaner and easier to maintain.
Simple explanation: Imagine you have a letter template. You fill in the name and date each time you send it. Jinja2 does that for web pages โ it fills in the blanks with data from your Python code.
How to use:
templates in your project.home.html.render_template() in your view function.Example:
from flask import render_template
@app.route('/')
def home():
return render_template('home.html')
Real-life example: A restaurant prints menus with today's specials filled in โ the menu is the template, the specials are the data.
School example: Your teacher gives you a worksheet template with blanks to fill in.
Home example: You use a greeting card template and write different messages each time.
Nigerian example: A business uses a template for invoices, filling in customer details each time.
Illustration:
TEMPLATE RENDERING
+-------------------------------------------------+
| app.py (Python) โ render_template('home.html') |
| โ |
| templates/home.html (HTML with Jinja2) |
| โ |
| Final HTML sent to browser |
| (All placeholders replaced with data) |
+-------------------------------------------------+
Mini summary: Jinja2 templates allow you to separate
HTML design from Python logic. Use render_template() to
render them.
Definition: You can pass variables from your Python
view function to the template to display dynamic content. This is done
using keyword arguments in render_template().
Why it is important: This is how you make your web pages personal and data-driven. Without this, your pages would be static and boring.
Simple explanation: You have a name tag. You write the person's name on it each time. Passing data to a template is like writing the name on the tag.
How to do it:
@app.route('/greet/<name>')
def greet(name):
return render_template('greet.html', name=name)
Template (greet.html):
<h1>Hello, {{ name }}!</h1>
You can also pass multiple variables:
@app.route('/profile')
def profile():
user = {"name": "Ada", "age": 12, "city": "Lagos"}
return render_template('profile.html', user=user)
Real-life example: A personalised email with the recipient's name and order details.
School example: A report card with the student's name and grades.
Home example: A birthday card with the person's age.
Nigerian example: A banking app shows your account balance and recent transactions when you log in.
Illustration:
PASSING DATA TO TEMPLATE
+-------------------------------------------------+
| Python: render_template('page.html', name=name) |
| โ |
| Template: <h1>Hello, {{ name }}!</h1> |
| โ |
| Output: <h1>Hello, Ada!</h1> |
+-------------------------------------------------+
Mini summary: Pass variables to templates using keyword
arguments in render_template(). Use {{ variable }}
in the template to display them.
Definition: Web forms allow users to submit data to your application. You can handle these submissions using GET (for retrieving data) or POST (for submitting data).
Why it is important: Forms are how users interact with your app โ like logging in, searching, submitting comments, or making orders.
Simple explanation: GET is like asking a question (the data is visible in the URL). POST is like handing in a form (data is hidden in the request body).
How to handle POST:
from flask import request
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
return f"Welcome, {username}!"
return render_template('login.html')
Real-life example: A login page where you submit your username and password.
School example: You fill in a form to register for a club or event.
Home example: You fill in a delivery address on a food delivery website.
Nigerian example: A banking app asks for your PIN using a secure form.
Illustration:
POST REQUEST HANDLING
+-------------------------------------------------+
| GET: user visits /login โ see form |
| POST: user submits form โ process data |
| request.form['username'] โ gets the value |
+-------------------------------------------------+
Mini summary: Use methods=['GET', 'POST']
to handle both. Use request.form to access submitted data
for POST requests.
Definition: Static files are files that do not change, like CSS stylesheets, images, and JavaScript files. They are served directly to the browser.
Why it is important: They make your website look beautiful and interactive. Without them, your site would be plain text.
Simple explanation: Think of a book cover โ it is static but makes the book attractive. Static files are like that for your website.
How to use:
static in your project.url_for('static', filename='style.css').Example:
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<img src="{{ url_for('static', filename='images/logo.png') }}" alt="Logo">
Real-life example: A website with a logo, custom fonts, and a beautiful colour scheme.
School example: A project report with a cover page and images.
Home example: A photo frame holding a picture.
Nigerian example: A business website with its company logo and brand colours.
Illustration:
STATIC FOLDER STRUCTURE
+-------------------------------------------------+
| project/ |
| โโโ app.py |
| โโโ templates/ |
| โ โโโ home.html |
| โโโ static/ |
| โโโ css/ |
| โ โโโ style.css |
| โโโ images/ |
| โโโ logo.png |
+-------------------------------------------------+
Mini summary: Place static files in a static
folder. Reference them using url_for('static', filename='...').
Definition: A well-organized project structure makes your code maintainable, scalable, and easy for others to understand.
Why it is important: As your project grows, good organization helps you find files quickly and avoid chaos. It also makes collaboration easier.
Simple explanation: Like having different drawers for different types of clothes โ it is easier to find what you need.
Recommended structure:
my_flask_app/
โโโ app.py
โโโ templates/
โ โโโ base.html
โ โโโ index.html
โโโ static/
โ โโโ css/
โ โ โโโ style.css
โ โโโ images/
โโโ venv/
โโโ requirements.txt
โโโ .gitignore
Best practices:
templates folder.static folder.requirements.txt for dependencies..gitignore file for Git.Real-life example: A library organizes books by genre and author for easy finding.
School example: Your folders for each subject.
Home example: Your kitchen drawers for cutlery, pots, and pans.
Nigerian example: A market where different sections sell different goods (e.g., food section, clothing section).
Illustration:
GOOD PROJECT STRUCTURE
+-------------------------------------------------+
| my_app/ |
| โโโ app.py (main logic) |
| โโโ templates/ (HTML files) |
| โโโ static/ (CSS, JS, images) |
| โโโ venv/ (virtual environment) |
| โโโ requirements.txt (dependencies) |
| โโโ .gitignore (what to ignore in Git) |
+-------------------------------------------------+
Mini summary: Organize your project with separate
folders for templates, static files, and environment. Use
requirements.txt to track dependencies.
Definition: Template inheritance allows you to create a base template that contains the common layout (like header and footer), and then extend it in other templates.
Why it is important: It avoids repetition. You write the layout once and reuse it across all pages. This makes maintenance much easier.
Simple explanation: Imagine you have a school uniform. Everyone wears the same base uniform, but each student can have their own tie or badge. The base template is like the uniform, and the child templates add the unique parts.
How to use:
Base template (base.html):
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}My App{% endblock %}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<header><h1>My App</h1></header>
<main>{% block content %}{% endblock %}</main>
<footer>© 2025 My App</footer>
</body>
</html>
Child template (home.html):
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block content %}
<h2>Welcome to My App!</h2>
<p>This is the home page.</p>
{% endblock %}
Real-life example: A restaurant chain has a consistent layout for all its branches, but each branch has its own menu.
School example: Your school's website has the same header and footer on every page, but each page has different content.
Home example: A magazine has the same cover design but different articles inside.
Nigerian example: A business website keeps the same logo and navigation on all pages.
Illustration:
TEMPLATE INHERITANCE
+-------------------------------------------------+
| base.html (layout: header, footer) |
| โ |
| โโโโโโโโดโโโโโโโฌโโโโโโโโโโโโโโโ |
| โ โ โ |
| V V V |
| home.html about.html contact.html |
+-------------------------------------------------+
Mini summary: Use template inheritance to avoid repeating HTML code. Create a base template and extend it in other templates.
Now we will build a complete Flask application that demonstrates everything we have learned.
Scenario: A simple "Greeting App" where a user enters their name and gets a personalized greeting. We will use template inheritance, static files, and form handling.
Code (app.py):
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/greet', methods=['GET', 'POST'])
def greet():
if request.method == 'POST':
name = request.form.get('name', 'Guest')
return render_template('greet.html', name=name)
return render_template('form.html')
if __name__ == '__main__':
app.run(debug=True)
templates/base.html:
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}Greeting App{% endblock %}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<nav><a href="/">Home</a> | <a href="/greet">Greet</a></nav>
<main>{% block content %}{% endblock %}</main>
<footer>© 2025 Greeting App</footer>
</body>
</html>
templates/home.html:
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block content %}
<h1>Welcome to the Greeting App!</h1>
<p>Enter your name and get a personalized greeting.</p>
<a href="/greet">Go to Greeting Form</a>
{% endblock %}
templates/form.html:
{% extends "base.html" %}
{% block title %}Greeting Form{% endblock %}
{% block content %}
<h1>Enter Your Name</h1>
<form method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name">
<button type="submit">Greet Me!</button>
</form>
{% endblock %}
templates/greet.html:
{% extends "base.html" %}
{% block title %}Greeting{% endblock %}
{% block content %}
<h1>Hello, {{ name }}!</h1>
<p>Welcome to the Greeting App.</p>
<a href="/greet">Go back</a>
{% endblock %}
static/css/style.css:
body {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-}
nav {
margin-bottom: 20px;
padding: 10px;
background-border-radius: 5px;
}
nav a {
text-decoration: none;
}
form {
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
button {
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
footer {
margin-top: 20px;
text-align: center;
}
What we used:
url_for() for links and static filesIllustration:
COMPLETE APP FLOW
+-------------------------------------------------+
| Home โ / โ Shows welcome page |
| Click "Go to Greeting Form" โ /greet (GET) |
| Fill form and submit โ /greet (POST) |
| Shows personalized greeting |
+-------------------------------------------------+
Mini summary: The complete app combines routes, templates, inheritance, static files, and form handling to create a professional-looking web application.
Definition: Deployment means making your app available on the internet so others can access it.
Why it is important: Sharing your app with the world is the final exciting step. It turns your project into something real that others can use.
Simple explanation: You have cooked a delicious meal. Now you want to serve it to your friends. Deployment is like serving your web app to users.
Options for deployment (free):
Steps for PythonAnywhere:
app.py file.yourusername.pythonanywhere.com.Important steps:
requirements.txt file.Real-life example: A business puts its website online for customers to visit.
School example: You present your project to the class.
Home example: You invite friends over to see your new garden.
Nigerian example: A local store opens an online shop so customers can order from anywhere.
Illustration:
DEPLOYMENT PROCESS
+-------------------------------------------------+
| Local development โ Upload to server โ Live! |
| (Your computer) (PythonAnywhere) (Internet) |
+-------------------------------------------------+
Mini summary: Deploy your Flask app using platforms like PythonAnywhere to share it with the world. Follow the steps to upload and configure your app.
| Word | Simple Definition |
|---|---|
| Web Framework | A set of tools for building web applications. |
| Flask | A lightweight web framework for Python. |
| Route | A URL path (e.g., /about). |
| View Function | A function that runs when a route is visited. |
| Template | An HTML file with placeholders for dynamic content. |
| Jinja2 | The templating engine used by Flask. |
| GET | An HTTP method for retrieving data. |
| POST | An HTTP method for submitting data. |
| Static File | A file that does not change, like CSS or images. |
| Template Inheritance | A way to reuse common HTML layout across pages. |
| Deployment | Making your app available on the internet. |
| Virtual Environment | An isolated space for managing dependencies. |
url_for() |
A Flask function that generates URLs for routes and static files. |
render_template() |
A Flask function that renders HTML templates with data. |
url_for() is the safe way to generate
URLs in Flask.
from flask import Flask.app = Flask(__name__).@app.route() decorator with the URL path.app.run(debug=True).templates folder.render_template.render_template('filename.html', var1=value1, var2=value2).{{ var1 }} to display the data.@app.route('/path', methods=['GET', 'POST']).if request.method == 'POST':.request.form['fieldname'].base.html with the common layout.{% block content %}{% endblock %} for replaceable sections.{% extends "base.html" %}.{% block content %}...{% endblock %}.url_for() to generate URLs safely.
| Mistake | How to Avoid It |
|---|---|
| Forgetting to install Flask | Always pip install flask in your virtual
environment. |
Not putting templates in the templates folder |
Flask expects templates to be in a folder named
templates (exact spelling). |
Using render_template without importing it |
Import from flask: from flask import render_template. |
Forgetting request.form for POST data |
Use request.form['field'] or
request.form.get('field'). |
| Not handling GET and POST correctly | Use methods=['GET', 'POST'] and check
request.method. |
Not using url_for for static files |
Always use {{ url_for('static', filename='...') }}
to ensure correct paths. |
| Forgetting to activate the virtual environment | Always activate the environment before installing or running. |
Using debug=True in production |
Only use debug mode during development. Set it to
False in production. |
templates
and static folders.
url_for() for linking to routes
and static files.
debug=True during development for
easier debugging.
requirements.txt to document
dependencies.
FLASK REQUEST-RESPONSE
+-------------------------------------------------+
| Browser sends request to /page |
| โ |
| Flask matches route to view function |
| โ |
| View function runs, maybe renders template |
| โ |
| Flask sends back HTML response |
| โ |
| Browser displays the page |
+-------------------------------------------------+
PROJECT STRUCTURE
+-------------------------------------------------+
| my_flask_app/ |
| โโโ app.py |
| โโโ templates/ |
| โ โโโ base.html |
| โ โโโ home.html |
| โโโ static/ |
| โ โโโ css/ |
| โ โ โโโ style.css |
| โ โโโ images/ |
| โโโ venv/ |
| โโโ requirements.txt |
| โโโ .gitignore |
+-------------------------------------------------+
GET VS POST
+-------------------------------------------------+
| GET: |
| - Data in URL (visible) |
| - Idempotent (safe to repeat) |
| - Used for retrieving data |
| - Can be bookmarked |
+-------------------------------------------------+
| POST: |
| - Data in request body (hidden) |
| - Not idempotent (should not be repeated) |
| - Used for submitting data |
| - Cannot be bookmarked |
+-------------------------------------------------+
TEMPLATE INHERITANCE
+-------------------------------------------------+
| base.html |
| โโโ header |
| โโโ {% block content %}{% endblock %} |
| โโโ footer |
| โ |
| โโโโโโโโดโโโโโโโฌโโโโโโโโโโโโโโโ |
| โ โ โ |
| V V V |
| home.html about.html contact.html |
| (fills (fills (fills |
| content) content) content) |
+-------------------------------------------------+
APP FLOW DIAGRAM
+-------------------------------------------------+
| User visits / โ home() โ home.html |
| โ |
| User clicks "Go to Greeting Form" |
| โ |
| User visits /greet (GET) โ form.html |
| โ |
| User fills form and submits (POST) |
| โ |
| greet() processes POST โ greet.html |
| โ |
| User sees personalized greeting |
+-------------------------------------------------+
| Feature | GET | POST |
|---|---|---|
| Purpose | Retrieve data | Submit data |
| Data location | URL query string | Request body |
| Visibility | Visible in URL | Not visible |
| Bookmarkable | Yes | No |
| Idempotent | Yes | No |
| Data size | Limited (URL length) | Unlimited |
| Use case | Search, pagination | Login, form submission |
| Feature | Flask | Django |
|---|---|---|
| Scope | Micro-framework | Full-stack framework |
| Learning curve | Easy | Steeper |
| Built-in features | Minimal (add as needed) | Admin, ORM, authentication |
| Flexibility | High | Moderate |
| Project size | Small to medium | Large, complex applications |
| Database ORM | SQLAlchemy (add-on) | Built-in |
| Best for | APIs, microservices, beginners | Content-heavy sites, CMS |
Lesson 1 Summary: A web framework simplifies building web applications by providing common tools.
Lesson 2 Summary: Flask is a lightweight, beginner-friendly Python web framework.
Lesson 3 Summary: Set up a virtual environment and install Flask to start developing.
Lesson 4 Summary: The basic Flask app has a route and a view function returning a response.
Lesson 5 Summary: Routes map URLs to view functions. Each route creates a page.
Lesson 6 Summary: Use Jinja2 templates with render_template() to generate HTML.
Lesson 7 Summary: Pass variables to templates using keyword arguments in render_template().
Lesson 8 Summary: Handle GET and POST methods; use request.form for POST data.
Lesson 9 Summary: Static files go in the static folder. Use url_for() to link them.
Lesson 10 Summary: Organize your project with templates, static, and a virtual environment.
Lesson 11 Summary: Template inheritance reuses common layout across pages.
Lesson 12 Summary: The complete app combines routes, templates, inheritance, static files, and forms.
Lesson 13 Summary: Deploy your app using PythonAnywhere or similar platforms to share it online.
Congratulations! You have completed Module One of Python Fundamentals Level Two ๐. You have taken the first step into the exciting world of web development with Flask.
You learned what a web framework is and why Flask is a great choice for beginners. You set up your development environment with a virtual environment and wrote your first Flask application. You learned about routes, view functions, templates, and how to pass data to them.
You handled forms with GET and POST requests, added static files to make your pages look professional, and organized your project correctly. You mastered template inheritance to avoid repeating HTML code. You even deployed your app so others could see it!
These are the foundational skills for building any web application. In the next module, you will dive deeper into Flask โ learning about databases, user authentication, and building more complex apps.
Keep practicing by building your own projects. The more you build, the better you will become. You are now a web developer! ๐
@app.errorhandler() to define custom
error pages. You can also use try-except blocks in your view
functions.
jsonify() to return JSON data.
request.files to handle uploaded files. Make
sure to set enctype="multipart/form-data" in your form.
url_for()?render_template() returns an HTML page. (True / False)templates folder. (True / False)url_for() is used to generate URLs in Flask. (True / False)request object is used to access form data. (True / False)app.run(debug=True) starts the Flask development server. (True / False)python install flask
pip install flask
install flask
flask install
@app.route('/')?
render()
render_template()
template()
html()
request.args.get()
request.form['name']
request.data
request.body
static
templates
public
assets
@app.get()
@app.route()
@app.post()
@app.view()
dependencies.txt
requirements.txt
packages.txt
pip.txt
debug=True in app.run()?
/user/<name>
/user/{name}
/user/%name%
/user:name
static folder
templates folder
views folder
app.py
url_for()
requirements.txt
Match the term on the left with its description on the right:
| Term | Description |
|---|---|
| 1. Flask | A. A lightweight Python web framework |
| 2. Route | B. A URL pattern |
| 3. View Function | C. A function that handles a request |
| 4. Template | D. An HTML file with placeholders |
| 5. Jinja2 | E. The templating engine used by Flask |
| 6. GET | F. An HTTP method for retrieving data |
| 7. POST | G. An HTTP method for submitting data |
| 8. Static | H. Folder for CSS, images, etc. |
| 9. Deployment | I. Making your app available online |
| 10. Template Inheritance | J. Reusing common HTML layout |
Answers: 1-A, 2-B, 3-C, 4-D, 5-E, 6-F, 7-G, 8-H, 9-I, 10-J
url_for() in Flask?Scenario 1:
Ada wants to build a simple "Name Saver" app where users can enter their name and it is stored in a list. She wants to display all saved names on a page. What routes and templates would she need? Write the code for the routes and views.
Scenario 2:
Chidi wants to add a CSS file to make his app look beautiful. He has a
file called style.css in a folder called css.
How would he link it in his base template?
Scenario 3:
Zainab wants to deploy her Flask app to PythonAnywhere. She has already created an account. What are the key steps she needs to follow to get her app live?
Activity Title: Build a Simple Calculator Web App
Instructions:
Activity Title: Build a Personal Bio Page
Instructions:
Project Title: Build a Simple To-Do List App
Description:
Create a Flask application for a to-do list. The app should:
This project will reinforce your understanding of routes, forms, and templates.
Assignment Title: Build a Temperature Converter Web App
Instructions:
Challenge Title: Build a Simple Blog with Flask and SQLite
Extend your Flask skills by building a simple blog. The blog should:
posts table (id, title,
content, created_at).This challenge combines web development with database integration. Good luck!
Fill-in-the-Blank Answers:
pip install flaskrender_templatestaticurl_for()render_template()True or False Answers:
Multiple Choice Answers:
static folder and linked using url_for().
Congratulations on completing Module One of Level Two! ๐ You have laid a strong foundation in web development with Flask. In the next module, you will learn how to:
To prepare, review the concepts from this module and practice building small Flask apps. The more you practice, the easier it will be to learn the advanced topics.
Keep coding, keep exploring, and never stop learning. See you in the next module! ๐๐
๐ End of Module One โ Python Fundamentals Level Two ๐