Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Python
  • Python for AI: The Five Tools You Actually Need
  • Thinking Like a Python Architect in an AI-First World
  • Your First Python Program: print, Comments, sep and end
  • Set Up PyCharm for Python: Install, First Project and First Run
  • Run a Python File and Read the Error: Tracebacks in Three Steps
  • Python Data Types, Variables and Strings: Indexing, Slicing and f-strings
  • Python Operators: Arithmetic, Comparison, Logical, Membership, Identity and Precedence
  • Python Conditionals and Loops: if/elif/else, for, while, break and continue
  • Looping Over Real Data in Python: Dicts, Lists of Dicts, enumerate and zip
  • Checking AI-Written Python Code: A Six-Step Habit That Finds Three Hidden Faults
  • Python Basics Practice: Report Card, Shopping Cart and Password Checker from a Prompt
  • Python Functions: Parameters, Return, Scope (LEGB), *args and **kwargs
  • Type Hints on Python Functions: Parameters, Returns, None and Collections
  • Python lambda, map, filter, Modules and Packages (with pip and venv)
  • Python Functions Practice: Bonus Calculator, Product Pipeline and a Math Package
  • Python Lists, Tuples, Sets and Dicts, Plus Type Hints on Variables
  • Python Comprehensions: List, Dict, Set and Generator Expressions, Read as Loops
  • Python Class Methods, Static Methods and Properties: What Each One Receives
  • Python Classes and Objects: __init__, self and PEP 8 Names
  • Python Inheritance and Polymorphism: super(), Overriding and Duck Typing
  • Python Multiple Inheritance, the MRO and Mixins
  • Python Encapsulation and Special Methods: Underscores, __str__, __add__ and __len__
  • Python Composition, Abstract Classes and Dataclasses
  • Python OOP Practice: Design a Bank, an Employee System and a Library
  • Set Up a Python AI Project with uv, VS Code and an API Key in .env
  • uv and pyproject.toml: Start, Add, Run and Rebuild a Python Project
  • Python try and except Basics: Catch an Error and Keep Going
  • Read and Write a File in Python: open, with, Modes and Encoding
  • Python Custom Exceptions and Advanced Error Handling: raise, raise from and the Call Stack
  • Python Logging and Debugging: Levels, Handlers, logger.exception and breakpoint()
  • Python File Modes, pathlib and Context Managers: x, r+, rb, Path and __enter__/__exit__
  • Python CSV, JSON and Large Files: csv, json, yield Pipelines, tomllib and pickle
  • Python Practice: Build a Log File Analyzer and a File Organizer
  • Python Project Structure for AI-Assisted Development: Packages, config.py and AGENTS.md
  • Regular Expressions in Python: search, findall, Groups and Greedy vs Lazy
  • Testing Python Code with pytest: assert, parametrize, fixtures and pytest.raises
  • Async Python: async def, await, asyncio.gather and the Blocking Trap
  • Django, FastAPI or Flask? The Same Blog Feature in Three Shapes, and How to Choose
  • One Blog, Three Frameworks: Routing, Models, Templates and Layout in Django, FastAPI and Flask
  • Getting Started with Flask: Routes, Jinja2 Templates and WSGI in One Small App
  • Your First Flask App with uv: From an Empty Folder to a Page in Debug Mode
  • Flask Routes, Templates and url_for: Converters, Forms, Redirects and the Signed Session
  • Flask-SQLAlchemy Models and Flask-Migrate: From a Python Class to a Real Table
  • Building a Blog with an AI Coding Agent: Plan Mode, a Master Prompt and the First Review
  • Handing a Figma Design to an AI Agent: Compare the Files, Then Review the Change
  • Inside a Flask Blog: The App Factory, Blueprints, the Instance Folder and CORS Done Right
  • How a Request and a Login Flow Through a Flask Blog: Flask-Login, CSRF and the Signed Session
  • Testing a Flask Blog with pytest: A Test App from the Factory, Fixtures and the Test Client
  1. Blog
  2. /
  3. Python
  4. /
  5. Advanced Python

Your First Flask App with uv: From an Empty Folder to a Page in Debug Mode

uv init, uv add flask, a five-line main.py and flask --app main run --debug. What each of the seven packages does, what the lock file pins, and what the 200 and 404 log lines tell you.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Advanced Python

What you will learn

  • Create a Flask project with uv init and uv add
  • Explain what pyproject.toml and uv.lock each record
  • Run an app with flask --app main run --debug and read every line it prints
  • Recognise the reloader, the debugger and why debug mode stays on your own machine

Before you start

  • Getting started with Flask
  • uv basics

This is the project the whole Flask blog grows out of. We start with an empty folder, install Flask with uv, write one small file and see a page in the browser. Two names stay fixed from here on: the file is main.py, and the object inside it is called app. That way every later lesson carries on with the same project.

If you haven't met Flask yet, read Getting started with Flask first. For uv itself, see Python project setup with uv.

A uv project

In an empty folder called S01L02_FirstApp, open the terminal and run:

uv init --bare
Initialized project `s01l02-firstapp`

--bare creates just one file, pyproject.toml. uv took the folder name, made it lowercase and swapped the underscore for a dash.

Older tutorials do three steps here: create a virtual environment, activate it, then pip install. uv handles all of that for you. (If you want to see what the old way does under the hood, Python virtual environments walks through it.)

Installing Flask

uv add flask
Using CPython 3.12.14
Creating virtual environment at: .venv
Resolved 8 packages in 12ms
Installed 7 packages in 77ms
 + blinker==1.9.0
 + click==8.5.1
 + flask==3.1.3
 + itsdangerous==2.2.0
 + jinja2==3.1.6
 + markupsafe==3.0.4
 + werkzeug==3.1.9

uv picked Python 3.12, created .venv and installed Flask 3.1.3. Flask brings six helper packages along:

PackageWhat it does
Werkzeugrequests, responses and the development server
Jinja2renders templates
Clickgives you the flask command
ItsDangeroussigns data, like the session cookie
MarkupSafekeeps text safe inside templates
Blinkersends signals (you won't need it for a while)

Seven packages in total. That short list is why Flask feels light.

pyproject.toml and uv.lock

uv add wrote Flask into the dependencies list:

[project]
name = "s01l02-firstapp"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
    "flask>=3.1.3",
]

Next to it, uv.lock appeared. It pins the exact version of every package, so anyone who opens the folder gets the same setup. That's the job a requirements file used to do with pip freeze. To check what's installed:

uv pip show flask
Name: flask
Version: 3.1.3
Location: S01L02_FirstApp\.venv\Lib\site-packages
Requires: blinker, click, itsdangerous, jinja2, markupsafe, werkzeug
Required-by:

So pyproject.toml says what you want, and uv.lock records exactly what you got.

The app in main.py

Add a new file at the top of the folder, main.py:

from flask import Flask

app = Flask(__name__)


@app.route("/")
def home():
    return "Hello blog, my first app."

Line by line: import the Flask class. Create the application object; __name__ tells Flask where the app lives so it can find templates and static files next to it later. @app.route("/") registers the function below it for the home page. home returns one plain line of text. That's a complete Flask app.

Running it

uv run flask --app main run --debug --port 8000
 * Serving Flask app 'main'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:8000
Press CTRL+C to quit
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 123-456-789
127.0.0.1 - - "GET / HTTP/1.1" 200 -
127.0.0.1 - - "GET /nothing HTTP/1.1" 404 -
  • uv run starts the command inside the virtual environment, so there's nothing to activate.
  • --app main tells Flask which file to load: the file name without .py. Flask finds the app object inside it. If the name doesn't match your file, Flask says it could not import it, so that's the first thing to check.
  • The warning says this is a development server. Fine on your machine; a deployed site uses a production server.
  • 127.0.0.1 is your own computer, followed by the port.

Two requests: 200 and 404

GET / matches the rule for slash, home runs, and the response is 200 text/html with Hello blog, my first app. GET /nothing matches no rule, and Flask answers 404 on its own. Browser GET / Rule "/" matches home() runs 200 text/html Hello blog, my first app. Browser GET /nothing No rule matches 404 not found you wrote no code for this
One rule, two requests. Any URL without a route gets a 404 from Flask itself.

Open the address in the browser. It sends GET /, Flask matches / to home, and the response comes back with status 200 and a content type of text/html; charset=utf-8. The page shows Hello blog, my first app., and the terminal logs one line for that request. That log line is how you'll check your requests from now on.

Ask for /nothing and there's no rule to match, so Flask answers 404 on its own.

What --debug gives you

  • Restarting with stat: the reloader is on. Save main.py and the server restarts by itself, so you just refresh the browser.
  • Debugger is active: if your code raises an error, the browser shows the full traceback with the line that failed.
  • Debugger PIN: protects that page. The debugger can run code on the server, so keep debug mode for your own machine and never switch it on for a deployed site.

Press Ctrl+C in the terminal to stop the server.

The project folder

ItemJob
main.pythe app
pyproject.tomlwhat the project needs
uv.lockthe exact versions
.venvPython and the seven packages; never edit it or share it, uv sync rebuilds it from the lock file

Common mistakes

  • --app doesn't match the file. --app main needs main.py. Otherwise Flask can't import the app.
  • Debug mode on a public server. The debugger can run code on the machine.
  • Committing .venv. Commit pyproject.toml and uv.lock; the environment is rebuilt from them.

Try it yourself

Change the text that home returns, save the file and refresh the browser: the reloader picks it up. Then add a second route for /about and open it. The next step is routes, templates and url_for.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in Python · 41 of 48

Previous
Getting Started with Flask: Routes, Jinja2 Templates and WSGI in One Small App
Next post
Flask Routes, Templates and url_for: Converters, Forms, Redirects and the Signed Session

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

Regular Expressions in Python: search, findall, Groups and Greedy vs Lazy

A regex is a stencil for a shape of text. Watch it slide and back up, build patterns with \d, \w, quantifiers and anchors, use search, findall, sub and split, pull parts out with named groups, and test AI-written patterns on edge cases.

Testing Python Code with pytest: assert, parametrize, fixtures and pytest.raises

A test is a line on a checklist your code must pass every time. Catch a discount bug with assert, read the E lines in the pytest report, cover cases with parametrize, share a cart with a fixture, test errors with pytest.raises, and see why a passing test from an AI tool can prove nothing.

Async Python: async def, await, asyncio.gather and the Blocking Trap

One cook, several pots: async lets one program wait on many things at once. See what async def and await really do, why three awaits in a row are no faster, how gather and TaskGroup bring 0.6 seconds down to 0.2, and the two mistakes that catch almost everyone.

Django, FastAPI or Flask? The Same Blog Feature in Three Shapes, and How to Choose

One small project lists two blog posts three times: as a Django view, a Flask route and a FastAPI endpoint. See each shape with its real output, what each framework includes, and a three-question way to choose.

On this page

  • A uv project
  • Installing Flask
  • pyproject.toml and uv.lock
  • The app in main.py
  • Running it
  • Two requests: 200 and 404
  • What --debug gives you
  • The project folder
  • Common mistakes
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.