Flask Tutorial
A complete Flask path from beginner to pro - lightweight Python web apps with routes, Jinja, SQLAlchemy, auth, APIs, and deployment.
Curriculum
Work through each section in order. Every lesson ends with practice and key points so the idea sticks.
Getting Started
- 1What is Flask?
Learn what Flask is, why it is called a microframework, and what kinds of Python web apps it can build.
8 min - 2Flask vs Django (When to Choose)
Compare Flask and Django so you can choose the right Python web framework for different beginner projects.
9 min - 3Install Flask & Virtual Environments
Set up a Flask 3.x project with a virtual environment, install Flask, and confirm the command line tools work.
12 min - 4Your First Flask App
Create a first Flask app with routes, simple responses, and the modern `flask --app` command.
12 min - 5Dev Server, Debug Mode & Reloader
Use the Flask development server safely, understand debug mode, and work with the automatic reloader.
10 min
Routing
- 6Routes & View Functions
Learn how Flask routes map URLs to view functions and how to organize simple page handlers.
11 min - 7Dynamic Routes & Converters
Use dynamic URL segments and converters to capture values from paths in Flask routes.
11 min - 8GET, POST & Other Methods
Understand HTTP methods and configure Flask routes that respond to GET, POST, and other request types.
12 min - 9url_for & Endpoint Names
Generate URLs with `url_for()` instead of hardcoding paths in Flask views and templates.
10 min
Request & Response
- 10The request Object
Read query strings, form data, headers, and JSON input from Flask requests.
12 min - 11Responses, JSON & Status Codes
Return strings, HTML, JSON, tuples, response objects, and meaningful status codes from Flask views.
12 min - 12Redirects & abort()
Send users to another URL with redirects and stop requests with `abort()` for standard error responses.
10 min
Templates
- 13Jinja2 Templates Basics
Render HTML templates with Flask and pass Python data into Jinja2 pages.
13 min - 14Template Inheritance
Create a shared base template with Jinja blocks so pages can reuse layout, navigation, and structure.
12 min - 15Template Filters & Control Structures
Use Jinja filters, if statements, loops, and empty states to make templates more expressive.
12 min - 16Static Files (CSS/JS/Images)
Serve CSS, JavaScript, and images from Flask's `static/` folder and link to them with `url_for()`.
10 min
Forms & Feedback
- 17HTML Forms with Flask
Build plain HTML forms, submit them to Flask routes, validate simple input, and redirect after POST.
14 min - 18Flask-WTF & WTForms
Use Flask-WTF and WTForms for structured form classes, validation, CSRF protection, and cleaner templates.
14 min - 19Flash Messages
Show one-time success, error, and info messages after redirects with Flask's flashing system.
10 min
State
- 20Sessions
Store small pieces of user-specific state with Flask sessions, such as display names or simple preferences.
12 min - 21Cookies
Read, set, and delete browser cookies in Flask while understanding how cookies differ from sessions.
10 min - 22Custom Error Pages
Create friendly custom pages for common Flask errors such as 404 Not Found and 500 Server Error.
11 min
App Structure
- 23Configuration Basics
Manage Flask configuration values for secrets, debug settings, feature flags, and environment-specific behavior.
12 min - 24Application Factory Pattern
Structure Flask apps with a `create_app()` function so configuration, tests, extensions, and blueprints are easier to manage.
14 min - 25Blueprints Intro
Organize related routes with Flask blueprints and register them in an application factory.
13 min
Database
- 26Flask-SQLAlchemy Setup
Install Flask-SQLAlchemy, configure a database URL, and initialize the extension with the application factory pattern.
12 min - 27Models & Tables
Define SQLAlchemy models with columns, constraints, defaults, and helpful representation methods.
13 min - 28Flask-Migrate & Alembic
Use Flask-Migrate to create, review, and apply Alembic migrations as your database schema changes.
14 min - 29CRUD with SQLAlchemy
Build create, read, update, and delete routes using SQLAlchemy sessions and Flask redirects.
15 min - 30Model Relationships
Connect models with one-to-many and many-to-many relationships using foreign keys and relationship attributes.
15 min - 31Querying Like a Pro
Write focused SQLAlchemy queries with filters, ordering, joins, pagination, eager loading, and aggregate counts.
16 min
Auth
- 32Password Hashing
Store passwords safely with Werkzeug hashing helpers and never keep raw passwords in the database.
10 min - 33Flask-Login
Add session-based user authentication with Flask-Login, user loaders, login_user, logout_user, and current_user.
13 min - 34Signup, Login & Logout Flows
Put practical authentication routes, templates, validation, flash messages, and redirects together.
16 min - 35Protecting Routes & Roles
Restrict pages to logged-in users and add role-based authorization decorators for admin-only behavior.
12 min
App Features
- 36File Uploads
Accept uploaded files safely, validate filenames and extensions, store files, and serve uploaded assets.
14 min - 37Sending Email
Configure Flask-Mailman style SMTP settings, send transactional email, and keep email sending testable.
12 min - 38Pagination
Split long result sets into pages using Flask-SQLAlchemy paginate() and build page navigation links.
11 min - 39Search & Filtering
Build search and filter routes that compose SQLAlchemy conditions from query string parameters.
14 min
APIs
- 40REST API Basics with Flask
Design resource-oriented Flask routes with HTTP methods, status codes, and JSON responses.
13 min - 41Building JSON APIs
Create consistent JSON serialization, request validation, and response envelopes for Flask APIs.
14 min - 42API Error Handling
Return useful JSON errors with custom error handlers, abort descriptions, validation errors, and database rollback.
12 min - 43CORS for Frontend Apps
Configure Cross-Origin Resource Sharing so browser frontends can call your Flask API safely.
11 min
Tooling
Quality
- 46Testing Flask Apps
Write pytest tests for Flask routes, app factories, database behavior, and authenticated clients.
16 min - 47before_request & Context Processors
Use Flask request hooks and context processors to prepare request data and share template helpers.
12 min - 48Useful Flask Extensions
Choose common Flask extensions for forms, auth, databases, APIs, admin panels, caching, and background jobs.
10 min
Quality & Safety
- 49Flask Security Essentials
Protect a Flask application with safe configuration, password hashing, session settings, authorization checks, and production habits.
18 min - 50CSRF, XSS & Secure Headers
Defend Flask forms and templates against CSRF, XSS, clickjacking, MIME sniffing, and common browser-side security mistakes.
17 min
Pro Architecture
- 51Structuring Larger Flask Apps
Organize a larger Flask codebase with an application factory, extensions module, feature packages, service functions, and clear boundaries.
18 min - 52Blueprints at Scale
Use Flask blueprints for large features, nested URL design, error handlers, template organization, and reusable registration patterns.
16 min - 53Environments & Secrets
Manage development, testing, staging, and production configuration without leaking secrets or hard-coding deployment values.
16 min
Shipping
- 54Deploying Flask (Gunicorn & Beyond)
Prepare Flask for deployment with a WSGI entrypoint, Gunicorn, environment variables, process management, logging, and health checks.
18 min - 55PostgreSQL with Flask
Connect Flask to PostgreSQL with SQLAlchemy, environment database URLs, migrations, connection pooling, and production-safe query habits.
17 min - 56Static Assets in Production
Serve CSS, JavaScript, images, and uploaded media efficiently with cache headers, hashed filenames, CDNs, and clean Flask template links.
14 min
Performance
- 57Caching Strategies
Improve Flask response time with safe caching layers, cache keys, Redis-style stores, invalidation habits, and template fragment caching.
17 min - 58Background Tasks (Celery-style Intro)
Understand when Flask work should move out of the request cycle and how Celery-style workers, queues, retries, and task status fit together.
18 min - 59Performance Mindset
Find Flask performance problems with measurement, query tuning, pagination, response size reduction, and request lifecycle awareness.
16 min
Capstone Projects
- 60Mini Project: Blog App
Build a small but production-shaped Flask blog with an app factory, blueprints, SQLAlchemy models, templates, forms, and publishing flow.
20 min - 61Mini Project: JSON API
Build a small Flask JSON API with versioned blueprints, request validation, SQLAlchemy persistence, JSON errors, and curl-based testing.
20 min - 62Mini Project: SaaS Dashboard Shell
Build a SaaS-style Flask dashboard shell with application layout, login-protected pages, organizations, settings, and extension points.
20 min
Polish & Next Steps
- 63Common Flask Mistakes (and Fixes)
Recognize frequent Flask problems around globals, debug mode, database sessions, templates, forms, blueprints, and production readiness.
15 min - 64Flask Ecosystem & When to Use Flask
Understand the Flask extension ecosystem and decide when Flask is a strong fit compared with larger frameworks or async-first tools.
14 min - 65What to Learn After Flask
Choose a practical learning path after Flask: testing, databases, security, deployment, APIs, frontend integration, and system design.
13 min