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:

text
  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:

text
  Gunicorn (HTTP)  →  WSGI  →  Flask application  →  your views

Code explanation:

  • Development uses flask run (Werkzeug server)—fine for learning, not for production
  • Deployment chapters use Gunicorn behind Nginx

Flask vs Django vs FastAPI

FlaskDjangoFastAPI
StyleMicroframework, you assembleBatteries includedAsync API-first
Admin, ORMVia extensionsBuilt-inVia extensions
TemplatesJinja2 (built-in)Django templatesUsually JSON only
Best forAPIs + small/medium sitesLarge CMS, admin-heavy appsHigh-concurrency async APIs
This trackMain focusMentioned onlyCompare 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:

bash
python --version

Install paths are in the next chapter; see Python installation for your OS.

Hello Code Learning Path

text
Python basics → Flask (this track) → MySQL + SQLAlchemy
       ↓              ↓                    ↓
    pip/venv      routes/templates      data layer
       ↓              ↓                    ↓
     Git           auth/deploy          production DB
TrackRole
PythonLanguage syntax
MySQLSQL and schema
GitVersion control
LinuxServer deploy
NginxReverse proxy
VueSPA frontend consuming JSON APIs (CORS chapter pairs with Vue 17)

Minimal Preview

You will write code like this in chapter 3:

python
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.route registers 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

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.