Python Academy · Lesson

Building a Simple Web App

Create your first web application using Flask.

Lesson 3 of 411 steps

Building a Simple Web App is a free Python Academy lesson on CoddyKit. This is lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, and your progress syncs across the web and the CoddyKit app. The Python Academy course includes 4 lessons in total.

Building a Simple Web App

Now that you’ve learned the basics of Flask, it’s time to build a simple web application. This app will include multiple routes, HTML templates, and some interactivity.

In this lesson, we’ll create a basic web app step by step.

Building a Simple Web App — illustration 1

Step 1: Setting Up the Project

Create a new folder for your project and initialize a virtual environment:

python -m venv venv

Activate the virtual environment and install Flask:

pip install flask
# Setting up the project
from flask import Flask

app = Flask(__name__)
print("Project setup complete")

Step 2: Creating the App Structure

Create the following folders and files:

  • app.py: Main application file.
  • templates/: Folder for HTML templates.
  • static/: Folder for static files like CSS and images.

Step 3: Defining Routes

In app.py, define routes for the home page and an about page:

# Defining routes
from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
    return '<h1>Welcome to My Web App</h1>'

@app.route('/about')
def about():
    return '<h1>About This App</h1>'

if __name__ == '__main__':
    app.run(debug=True)

Step 4: Adding Templates

Create an HTML file named home.html inside the templates/ folder:

<!-- home.html -->
<!DOCTYPE html>
<html>
<head>
    <title>Home</title>
</head>
<body>
    <h1>Welcome to My Web App</h1>
    <a href="/about">About</a>
</body>
</html>

Step 5: Using render_template

Update the home and about routes to use the templates:

# Using templates
from flask import render_template

@app.route('/')
def home():
    return render_template('home.html')

@app.route('/about')
def about():
    return render_template('about.html')

Step 6: Adding Static Files

Create a style.css file inside the static/ folder and link it in home.html:

/* style.css */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f9;
    color: #333;
}

Step 7: Running the App

Run your Flask application:

python app.py

Open your browser and navigate to http://127.0.0.1:5000/ to see your web app in action.

Common Mistakes When Building Web Apps

Here are some mistakes to avoid:

  • Not organizing the app structure (e.g., missing templates/ and static/ folders).
  • Hardcoding URLs instead of using url_for().
  • Not testing the app in debug mode.

What Did We Learn?

In this lesson, you learned:

  • How to set up a Flask project structure.
  • How to define routes and use templates.
  • How to include static files like CSS in your app.
  • How to run your Flask application and view it in a browser.

Great job! Let’s move to the next topic.

Building a Simple Web App — illustration 11
Free to start

Learn Python with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
76
Lessons
320

Frequently Asked Questions

Is the “Building a Simple Web App” lesson free?

Yes — the full text of “Building a Simple Web App” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO. The Python Academy course includes 4 lessons in total.

What will I learn in “Building a Simple Web App”?

Create your first web application using Flask. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Python Academy?

No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Building a Simple Web App” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Python Academy lesson?

Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Basics of Web Frameworks
  2. Introduction to Flask
  3. Building a Simple Web App
  4. Connecting Python to Databases
← Back to Python Academy