What Is Flask
Introduction
Flask is a Python web framework that stays small on purpose—you add only what your project needs. It handles HTTP routing, requests, responses, and hooks into Jinja2 templates, while leaving databases, auth, and admin panels to extensions you choose. This chapter explains what Flask is good for, how it compares to Django and FastAPI, and where this tutorial fits on Hello Code.
Prerequisites
- Basic Python knowledge: functions, modules, imports
- A terminal on Windows, macOS, or Linux
- No Flask installed yet for this overview
What Flask Does
When a browser requests a URL, Flask:
Browser Flask app (Python) Your code
│ │ │
│ GET /hello │ │
├───────────────────►│ match route │
│ ├───────────────────────►│ return "Hello"
│◄───────────────────┤ response │Code explanation:
- Flask maps URLs to Python functions called view functions
- The return value becomes the HTTP response body (HTML, JSON, or plain text)
Flask is a microframework: the core is tiny; you plug in Flask-SQLAlchemy, Flask-Login, and other packages as needed.
WSGI (Concept)
Production Python web apps speak WSGI—a standard interface between your Flask code and servers like Gunicorn:
Gunicorn (HTTP) → WSGI → Flask application → your viewsCode explanation:
- Development uses
flask run(Werkzeug server)—fine for learning, not for production - Deployment chapters use Gunicorn behind Nginx
Flask vs Django vs FastAPI
| Flask | Django | FastAPI | |
|---|---|---|---|
| Style | Microframework, you assemble | Batteries included | Async API-first |
| Admin, ORM | Via extensions | Built-in | Via extensions |
| Templates | Jinja2 (built-in) | Django templates | Usually JSON only |
| Best for | APIs + small/medium sites | Large CMS, admin-heavy apps | High-concurrency async APIs |
| This track | Main focus | Mentioned only | Compare only |
Many teams pick Flask when they want control and a flat learning curve before adding complexity.
Typical Use Cases
- REST APIs for mobile or SPA frontends
- Internal tools and dashboards
- Prototypes and hackathon demos
- Teaching HTTP and web architecture
- Microservices alongside Java Spring Boot or Node backends
Flask 3 and Python Version
Use Python 3.10+ and Flask 3.x:
python --versionInstall paths are in the next chapter; see Python installation for your OS.
Hello Code Learning Path
Python basics → Flask (this track) → MySQL + SQLAlchemy
↓ ↓ ↓
pip/venv routes/templates data layer
↓ ↓ ↓
Git auth/deploy production DB| Track | Role |
|---|---|
| Python | Language syntax |
| MySQL | SQL and schema |
| Git | Version control |
| Linux | Server deploy |
| Nginx | Reverse proxy |
| Vue | SPA frontend consuming JSON APIs (CORS chapter pairs with Vue 17) |
Minimal Preview
You will write code like this in chapter 3:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Flask!"
if __name__ == "__main__":
app.run(debug=True)Code explanation:
Flask(__name__)tells Flask where to find templates and static files@app.routeregisters a URL path- The function return value is sent to the client
Tip
Start Simple, Grow Deliberately
Flask projects often begin as one file, then split into Blueprints and an application factory—this track follows that path.
FAQ
Flask still popular?
Yes—widely used for APIs, data tools, and education; Flask 3 keeps the project modern.
Need Django first?
No—pick Django if you want an all-in-one framework day one; Flask if you want to see each layer clearly.
Async Flask?
Flask 3 supports async views in some cases; this track focuses on sync WSGI patterns that match most tutorials and deployments.
Flask vs FastAPI for APIs?
FastAPI excels at typed async APIs; Flask excels at mixed HTML + JSON apps and huge extension ecosystem.
Commercial use?
Flask is BSD-licensed—free for commercial projects.
Where is official docs?
Pallets Flask documentation—authoritative reference alongside this track.