This document details the main features of the Flask web framework, its dependencies, installation, and key differences from Django. It covers Flask’s extensibility, built-in tools, and popular community extensions for web development.
This document explores the core features of Flask, its dependencies, installation process, and how it compares to Django. It highlights Flask’s extensibility, built-in tools, and popular community extensions for building web applications.
Flask is a micro web framework for Python, designed to create web applications with minimal dependencies. It is unopinionated, allowing developers to choose their tools and extensions.
1python -m venv venv
2source venv/bin/activate
3pip install flask==2.2.2
| Feature | Description |
|---|---|
| Web Server | Runs apps in development mode |
| Debugger | Shows interactive traceback in browser |
| Logging | Uses Python logging for app and custom messages |
| Testing | Supports test-driven development |
| Request/Response | Enables argument parsing and custom responses |
Popular community extensions:
| Extension | Purpose |
|---|---|
| Flask-SQLAlchemy | Adds SQLAlchemy ORM support |
| Flask-Mail | Enables SMTP mail server integration |
| Flask-Admin | Adds admin interfaces |
| Flask-Uploads | Supports custom file uploads |
| Flask-CORS | Handles Cross-Origin Resource Sharing |
| Flask-Migrate | Adds database migrations |
| Flask-User | User authentication and management |
| Marshmallow | Object serialization/deserialization |
| Celery | Task queue for background jobs |
To view installed dependencies:
1pip freeze
| Aspect | Flask | Django |
|---|---|---|
| Type | Micro framework | Full-stack framework |
| Dependencies | Minimal, extensible | Includes all major features |
| Flexibility | Highly flexible, plug-and-play | Opinionated, less flexible |
| Use Case | Lightweight apps, custom solutions | Full-featured web applications |
Flask is a lightweight, extensible web framework with minimal dependencies and a rich ecosystem of extensions. Its flexibility and simplicity make it ideal for building modern web applications, while Django offers a more comprehensive, opinionated approach.
(1) Flask is a micro framework that is lightweight, flexible, and extensible.
(1) Pinning versions ensures the application can be reproduced and avoids unexpected issues from updates.
(4) Flask does not include a built-in ORM; this is provided by extensions like Flask-SQLAlchemy.
(1) Flask is designed to be extensible through a wide range of community extensions.
| Dependency | Purpose |
|---|---|
| A. Werkzeug | 1. Escapes untrusted input in templates |
| B. Jinja | 2. Implements WSGI interface |
| C. MarkupSafe | 3. Template language for rendering pages |
A-2, B-3, C-1.
(1) Flask is lightweight and flexible, while Django is full-featured and opinionated.
Flask can be extended with community packages to add features like ORM, mail, and admin interfaces.
True. Flask’s extensibility is one of its core strengths, supported by many community extensions.