Flask Tutorial
Last Updated : 08 Apr, 2025
Flask is a lightweight and powerful web framework for Python. It’s often called a "micro-
framework" because it provides the essentials for web development without unnecessary
complexity. Unlike Django, which comes with built-in features like authentication and an
admin panel, Flask keeps things minimal and lets us add only what we need.
This Flask tutorial covers everything from setup and installation to advanced topics like
authentication, database integration and deployment. You'll also find Flask project ideas,
FAQs and interview questions to help you prepare for job interviews.
1/4
Interesting Facts about Flask
Here are some interesting facts about Flask:
1. Microframework: Flask is considered a "micro" web framework
because it is lightweight and simple to use, with minimal dependencies.
It doesn't come with the full set of tools that more extensive
frameworks like Django provide, giving developers more control and
flexibility over the application structure.
2. Werkzeug and Jinja2: Flask is built on top of two powerful libraries:
Werkzeug: A comprehensive WSGI web server library that helps
manage the application's request and response cycles.
Jinja2: A templating engine that allows you to use dynamic HTML in
your application, making it easy to build web pages with variables and
loops.
3. Routing: Flask’s routing system is extremely simple and intuitive. You
define routes with decorators that map URLs to Python functions. This
makes it very easy to set up and control the flow of your application.
4. No ORM by Default: Unlike Django, Flask does not come with a built-
in Object-Relational Mapping (ORM) tool like Django’s ORM. Instead, it
lets developers choose their ORM, such as SQLAlchemy or simply use
raw SQL.
5. RESTful API Support: Flask is popular for building RESTful APIs. Its
simplicity and flexibility make it a great choice for building APIs and
many developers use it for creating microservices and backends for
single-page applications.
6. Development Server: Flask comes with a built-in development server
that makes it easy to test and run the application locally. This server is
lightweight and designed for use during development rather than
production.
Introduction to Flask
In this section, we’ll introduce Flask for web development, explore why it’s a micro web
framework and compare it with Django. We’ll also cover Flask installation, preparing you to
start building web applications.
Introduction to Web Development using Flask
Differences Between Django and Flask
Installation of Flask on Windows
Flask Quick Start
Welcome to Flask Quick Start - your go-to guide for mastering Flask development
essentials in a snap! From crafting your inaugural application to fine-tuning HTTP
methods, routes and redirects, this concise yet comprehensive resource equips you with
the skills needed to excel in Flask development.
Creating the first simple application
Run a Flask Application
Flask Routes
Flask Models
Flask – HTTP Method
Flask - Variable Rules
Redirects and URL
Redirect and Errors
Change Port in Flask app
Changing Host IP Address in Flask
Templates and Static Files in Flask
Templates in Flask are HTML files used to create dynamic web pages. Flask uses Jinja2, a
powerful templating engine, to embed Python logic in these templates. Static files
like CSS, JavaScript and images are stored separately to enhance the user interface. This
section covers how to use templates and static files effectively in Flask.
Templates in Flask
Template Inheritance
Static Files in Flask
Form Handling
Forms in Flask allow users to submit data, such as login credentials or search queries. Flask
handles forms using the request object to capture user input and process it on the server.
Flask uses Flask-WTF that simplifies validation and security. This section covers handling
forms, processing input and ensuring validation in Flask applications.
Flask-WTF
Handling File Uploads
CSFR Protection
Flask Configuration
In Flask, configurations help manage settings like debug mode, database connections and
secret keys. Instead of hardcoding these values, you can define them separately to make
your app more secure and adaptable for different environments such as development,
testing and production.
Flask App Configuration
Flask Environment-Specific Configuration
Database in Flask
Flask uses databases to store and manage data, with Flask-SQLAlchemy as its most
popular tool for handling relational databases like SQLite and PostgreSQL. It provides
an ORM (Object Relational Mapper) for easier database interactions while also supporting
raw SQL queries. Flask can also connect to NoSQL databases like MongoDB. This section
covers setting up databases, performing CRUD operations and integrating Flask with
different database systems.
Flask-SQLAlchemy
Flask SQLite
Sending Data from a Flask app to MongoDB Database
Making a Flask app using a PostgreSQL Database
Build a Web App using Flask and SQLite in Python
Login and Registration Project Using Flask and MySQL
Execute raw SQL in the Flask-SQLAlchemy
Middlewares in Flask
Flask middlewares process requests and responses before they reach the app or user. They
handle tasks like logging, authentication and request modifications. Though Flask lacks
built-in middleware support, you can use before_request, after_request and
teardown_request decorators or integrate WSGI middleware.
What are Middlewares in Flask
WSGI Middleware
Authentication in Flask
Flask handles user authentication with tools like Flask-Login for login, logout and session
management. Bcrypt secures passwords with hashing, while role-based access
control restricts user permissions. This section covers authentication basics, managing
sessions, displaying usernames and handling JSON responses.
How To Add Authentication to Your App with Flask-Login
Display Current Username in Flask
Password Hashing with Bcrypt in Flask
How to store username and password in Flask
Flask – Role-Based Access Control
Flask Sessions to server Logout
Flask - JWT
Flask Cookies
Flask - JSON Response
Rest APIs in Flask
Flask makes building REST APIs easy, handling requests
like GET, POST, PUT and DELETE. With Flask-RESTful or simple routes, you can send and
receive JSON data, manage authentication and secure your API. This section covers
creating and using REST APIs in Flask.
Creating Rest APIs
Flask RESTful Extension
Serialization and Deserialization
Advanced Topics
Flask supports advanced features for building high-performance applications.
Asynchronous programming with AsyncIO allows handling multiple tasks efficiently. Flask
WebSockets enable real-time communication for chat apps and live updates.
Asynchronous Programming with async.io
Web Sockets in Flask
Flask Blueprints
Flask Deployment and Error Handling
Delve into Flask with Python deployment and error handling, covering subdomain
management, 404 error handling, deploying Flask apps on Heroku and incorporating
machine learning models seamlessly.
Subdomain in Flask
Handling 404 Error in Flask
Dockerization
Deploy Python Flask App on Heroku
Deploy Machine Learning Model using Flask
Flask Projects
Explore a variety of Flask Web Framework projects, from a todo list app to sentiment
analysis on Twitter, showcasing diverse functionalities such as portfolio creation, MySQL
integration and interactive data visualization with graphs and charts.
Todo list app using Flask Python
Single Page Portfolio Using Flask
Profile Application using Python Flask and MySQL
Wikipedia search app using Flask Framework – Python
Twitter Sentiment Analysis WebApp Using Flask
Create Cricket Score API using Web Scraping in Flask
How to Add Graphs to Flask Apps
Flask Projects Archives
Difference Between Flask and Django
Here in this section, we have create a comparison table of Flask and Django.
Feature Flask Django
Framework Micro-framework (lightweight, Full-stack framework (includes built-in
Type minimal setup) features)
Flexibility Highly flexible, allows
Less flexible but provides a lot of built-in tools
customization
Developmen Slower for larger projects due to
Faster for large projects with built-in solutions
t Speed less automation
Learning Easier for beginners due to Steeper learning curve due to more complex
Curve simplicity features
Use Case Best for small to medium web
Best for large, complex applications
applications
Project
Simple, user-defined structure Follows a specific organized project structure
Structure
Built-in Minimal, requires third-party Comes with built-in features like ORM, admin
Features libraries panel and authentication
Scalability Requires more manual work for High scalability with built-in tools for large
scalability projects
ORM Optional (Flask-SQLAlchemy for
Built-in ORM (Django ORM)
Support database support)
Template Jinja2 Django Template Language
Feature Flask Django
Engine
Security Requires manual implementation Comes with built-in security features like
Features of many security features CSRF protection, user authentication
URL Automatic URL routing with pre-defined
Manual, more customizable
Routing patterns
Career Opportunities with Flask
Career Role Salary (INR) Salary
(USD) (Approx.)
Entry-Level Flask ₹3,00,000 - ₹5,00,000 per $3,600 - $6,000 per
Developer annum annum
Mid-Level Flask ₹5,00,000 - ₹9,00,000 per $6,000 - $10,800 per
Developer annum annum
Senior Flask Developer ₹9,00,000 - ₹15,00,000 per $10,800 - $18,000 per
annum annum
Lead ₹15,00,000 - ₹25,00,000 per $18,000 - $30,000 per
Developer/Architect annum annum
Must Read - Top 40 Flask Interview Questions and Answers
Comment
More info
Campus Training Program
Next Article
Introduction to Web development using Flask
Similar Reads
Java Tutorial
Java is a high-level, object-oriented programming language used to build applications
across platforms—from web and mobile apps to enterprise software. It is known for i...
15+ min read
Dart Tutorial
Dart is an open-source general-purpose programming language developed by Google. It
supports application development on both the client and server side. However, it is wid...
15+ min read
Flask - Variable Rule
Flask variable rules allow us to create dynamic URLs by defining variable parts within the
route. This makes it possible to capture values from the URL and pass them to vi...
15+ min read
Android Tutorial
In this Android Tutorial, we cover both basic and advanced concepts. So whether you are a
fresher (graduate) or an experienced candidate with several years of Android Deve...
15+ min read
Node.js Tutorial
Node.js is a powerful, open-source, and cross-platform JavaScript runtime environment
built on Chrome's V8 engine. It allows you to run JavaScript code outside the browser...
15+ min read
Solidity Tutorial
Solidity tutorial is designed for those who want to learn Solidity programming language and
for experienced Solidity developers looking to gain a deeper understanding of t...
15+ min read
Flask Tutorial for Data Science
Flask is a lightweight Python web framework that helps data scientists turn models and
analysis into interactive web applications. This tutorial covers how to use Flask fo...
15+ min read
jQuery Tutorial
jQuery is a lightweight JavaScript library that simplifies the HTML DOM manipulating, event
handling, and creating dynamic web experiences. The main purpose of jQuery is t...
15+ min read