Flask: Lightweight Web
Framework
Presented By
Name: Manas Pratap Singh
Roll no: 130410623015
Subject: Python with Machine Learning
Date: 11-11-2025
What is Flask?
Flask is often called a "micro" framework, but this doesn't mean it lacks functionality. It refers to the fact that
Flask keeps the core simple, allowing users to choose their own tools and extensions for complex needs.
Micro Web Framework Designed for Simplicity Versatile Applications
Written entirely in Python, Ideal for building small-to-
providing a solid foundation Focuses on being explicit and medium web applications,
without forcing dependencies. modular, which greatly improves robust REST APIs, and data
developer experience and dashboards.
learning curve.
Why Choose Flask for Your Project?
Flask’s modular nature and low barrier to entry make it the preferred choice for many developers.
Minimal Setup Full Control
Extremely quick to get a basic application running, Developers select components (like ORM and form
requiring only a few lines of code. validation), ensuring project lightweightness.
ML/AI Integration Rapid Prototyping
Perfectly suited for wrapping machine learning models Excellent for proof-of-concept projects and smaller,
as simple, accessible web services (APIs). focused applications.
Core Features and Capabilities
Flask provides essential tools while maintaining its lightweight philosophy through smart design choices.
Lightweight and Modular
No default dependencies on databases or specific template engines beyond its core
necessities.
Built-in Development Server
Includes a development server and debugger to simplify the local testing process.
RESTful Request Handling
Designed to handle HTTP requests and responses, making it ideal for modern API
development.
Jinja2 Templating
Integrates seamlessly with Jinja2 for dynamic HTML rendering.
Extensible Ecosystem
A vast array of community-maintained extensions allow for adding complex features easily.
Understanding the Flask Request Flow
The architecture is simple: the client initiates, Flask processes, and a response is returned.
Client Request View Processing
Client sends an HTTP request
View handles logic and DB
access
Send Response
Routing
Flask routes request to view Flask returns HTTP response
1. Client Request 2. Request Routing
User navigates to a URL, sending a request to the server. Flask matches the URL path to a specific Python function.
The Core Components of a Flask App
Flask App Object
The central instance of your application (usually app = Flask(__name__)). It is where all routing and configuration occurs.
Routing System (@[Link])
Decorators used to register functions to specific URLs, directing incoming traffic to the appropriate handler.
Templates (Jinja2)
Used to separate presentation logic from business logic, allowing for dynamic and reusable HTML.
Request & Response
Objects that encapsulate the incoming data from the client and the data sent back, respectively.
Blueprints
A way to structure larger applications into smaller, reusable modules or components (e.g., separating an authentication section).
First Look: A Minimal Flask Application
This simple application creates a single route ('/') that displays a welcome message. This is all you need to get started!
from flask import
Flaskapp = Flask(__name__)
@[Link]('/')
def home():
return "Welcome to Flask!"
if __name__ == '__main__':
[Link](debug=True)
How to Run
Save the code as [Link]. Run in your terminal with: python [Link]
Access the running application at: [Link]
Flask vs. Django: Choosing the Right Tool
While both are excellent Python frameworks, their core philosophies guide them toward different project sizes
and goals.
Type Micro Framework (Minimalist) Full-stack Framework ("Batteries
Included")
Flexibility High (You choose all external Medium (Strongly opinionated structure)
components)
Setup Simple and immediate start More complex, requires project creation
ORM Manual (Requires an extension like Built-in ORM with excellent admin
SQLAlchemy) interface
Best For Small-to-Medium Apps, APIs, Prototyping Large Enterprise Apps, Database-heavy
Websites
Essential Flask Extensions
These community-driven extensions demonstrate Flask's true power by adding complex functionality on demand.
Flask-SQLAlchemy
Simplifies database interactions using the popular SQLAlchemy ORM.
Flask-Login
Provides secure user session management and authentication handling.
Flask-Mail
Offers easy integration for sending emails from your web application.
Flask-WTF
Handles web forms, data validation, and CSRF protection.
Flask-RESTful
A clean and fast way to build REST APIs with Flask.
Thank You