Flask Tutorial
Build real websites and APIs with Flask, the lightweight Python web framework — 50 lessons from your first route to a deployed full-stack app.
Learn Flask from scratch — routes, templates, forms, databases, blueprints, REST APIs and authentication — free interactive Python web-dev lessons.
Part of the free Flask course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
👋 Know a little Python? You're ready for Flask.
Start with Lesson 1 and build a working web app step by step — at your own pace.
Lessons in this course
- Introduction to Flask — What Flask is, how to install it, and run your first web app with flask run
- Your First Route — Map URLs to Python functions with the @app.route decorator
- Dynamic Routes & Variables — Capture parts of the URL as variables and use type converters
- HTTP Methods (GET & POST) — Handle GET and POST requests and read submitted data
- Templates with Jinja2 — Render HTML pages with the Jinja2 templating engine
- Static Files (CSS, JS, Images) — Serve stylesheets, scripts, and images from the static folder
- Request & Response Objects — Inspect incoming requests and craft custom responses with headers and status codes
- Handling Forms — Collect, validate, and process user input from HTML forms
- Sessions & Cookies — Remember users across requests with signed sessions and cookies
- Flask Blueprints — Split a growing app into modular, reusable components
- Database with SQLAlchemy — Connect a database and define models with Flask-SQLAlchemy
- CRUD Operations — Create, read, update, and delete database records
- Database Migrations — Evolve your database schema safely with Flask-Migrate and Alembic
- Error Handling & Custom Pages — Catch errors and show friendly custom 404 and 500 pages
- Flashing Messages — Show one-time notifications like 'Saved!' after an action
- Building a REST API — Design RESTful endpoints that return JSON for any client
- JSON & Serialization — Convert Python objects to JSON and parse incoming JSON payloads
- Authentication & Login — Register, log in, and protect routes with Flask-Login and hashed passwords
- App Factory & Config — Structure production apps with the application factory pattern and config classes
- Testing Flask Apps — Write automated tests with the Flask test client and pytest
- Deploying Flask — Ship your app to production with Gunicorn and a real WSGI server
- Jinja2 Deep Dive: Filters, Macros & Inheritance — Master Jinja2 filters, loops, template inheritance, includes, and macros
- URL Building & Redirects with url_for — Generate URLs the safe way with url_for and redirect between views
- Working with Cookies — Set, read, and delete cookies with the right security flags
- Handling File Uploads — Accept file uploads safely with request.files and secure_filename
- Configuration & Environments — Manage settings with config objects, classes, and environment variables
- Application & Request Context (g, current_app) — Understand the app and request contexts, flask.g, and current_app
- Request Hooks (before/after_request) — Run code around every request with before_request and after_request
- Class-Based Views (MethodView) — Organize related handlers into classes with Flask's MethodView
- Checkpoint: A Dynamic Web App — Combine templates, cookies, hooks and class-based views — then a quiz
- User Login with Flask-Login — Add a login system with sessions, @login_required, and current_user
- Form Validation with Flask-WTF — Validate forms and block bad input with WTForms validators and CSRF
- SQLAlchemy Relationships — Model one-to-many and many-to-many relationships between tables
- Querying with SQLAlchemy — Filter, order, join, and aggregate with the modern select() API
- Pagination — Split long result sets into pages with offset/limit and page links
- CORS & Cross-Origin Requests — Allow browsers from other origins to call your API safely
- API Authentication with JWT — Issue and verify JSON Web Tokens to protect your API endpoints
- Serialization with Marshmallow — Serialize and validate API data with Marshmallow schemas
- Checkpoint: Build a REST API — Combine models, queries, schemas and pagination into a JSON API — then a quiz
- Caching with Flask-Caching — Speed up responses with view, memoize, and backend caching
- Rate Limiting (Flask-Limiter) — Protect APIs with per-route limits and 429 responses
- Background Tasks (Celery & RQ) — Offload slow work to a worker queue and return instantly
- Real-Time with WebSockets (Flask-SocketIO) — Push live updates with WebSocket events, rooms, and broadcasts
- Sending Email (Flask-Mail) — Send plain-text and HTML email with attachments from a request
- Logging & Monitoring — Configure app.logger, structured logs, and error reporting
- Custom CLI Commands (flask CLI) — Add your own flask commands with click options and arguments
- Signals (Blinker) — Decouple code by reacting to request and template signals
- Async Views & ASGI — Write async def views and run Flask under an ASGI server
- Checkpoint: Production-Ready Flask — Combine caching, rate limiting, tasks and logging — then a quiz
- Capstone: A Full CRUD App — Combine everything into a complete database-backed web application
- API Docs with OpenAPI & Swagger — Auto-generate interactive Swagger docs with flask-smorest and marshmallow schemas
- DB Transactions & Query Optimization — Commit/rollback safely, then speed queries with indexes and eager loading