What is Flask?
Flask is a lightweight WSGI (Web Server Gateway Interface) web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. Originally created as an April Fool's joke by Armin Ronacher, it has grown into one of the most popular Python web frameworks in the world.
The 'Micro' Philosophy
Flask is often called a 'micro-framework' because it does not require particular tools or libraries. It keeps the core simple but extensible. Unlike 'batteries-included' frameworks like Django, Flask doesn't force a specific database or form validation tool on you. You choose the components you need.
Core Components
- Werkzeug: A utility library for the Python programming language that handles routing, debugging, and WSGI details.
- Jinja2: A modern and designer-friendly templating engine for Python, used to render dynamic HTML.
- Click: A package for creating beautiful command-line interfaces, used for the
flaskcommand.
Hello World Example
A complete Flask application can be written in a single file. This simplicity is why many developers use it for prototyping and building REST APIs for mobile apps.
Flask vs. Django
| Feature | Flask | Django |
|---|---|---|
| Type | Micro-framework | Full-stack framework |
| Flexibility | High (Choose your tools) | Low (The 'Django' way) |
| Learning Curve | Very shallow | Steep |
| Admin Panel | Available via extensions | Built-in |
| Best For | Microservices, Small-Medium apps | Large Enterprise monoliths |