python-backend
/

Introduction to Flask – The Micro-Framework

Last Sync: Today

On this page

5
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

python-backend

Introduction to Flask – The Micro-Framework

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 flask command.

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.

PythonRead-only
1
from flask import Flask

# Initialize the application
app = Flask(__name__)

# Define a route
@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()

Flask vs. Django

FeatureFlaskDjango
TypeMicro-frameworkFull-stack framework
FlexibilityHigh (Choose your tools)Low (The 'Django' way)
Learning CurveVery shallowSteep
Admin PanelAvailable via extensionsBuilt-in
Best ForMicroservices, Small-Medium appsLarge Enterprise monoliths

Test Your Knowledge

Q1
of 3

Which templating engine does Flask use by default?

A
Mako
B
Mustache
C
Jinja2
D
EJS
Q2
of 3

What does it mean that Flask is a 'micro' framework?

A
It only works on small computers
B
It lacks a built-in database layer and other heavy components
C
It is written in a micro programming language
D
It can only handle one user at a time
Q3
of 3

Who created the Flask framework?

A
Guido van Rossum
B
Armin Ronacher
C
Mark Zuckerberg
D
Brendan Eich

Frequently Asked Questions

Is Flask only for small applications?

No. While it is 'micro', Flask is used by large companies like Netflix, Airbnb, and Reddit. Its modular nature allows you to add only the complexity you actually need.

Does Flask support Asynchronous (async/await)?

Yes. Since version 2.0, Flask supports asynchronous route handlers, though it remains a WSGI framework at its core. For purely asynchronous performance, some developers look at FastAPI.

What is WSGI?

WSGI (Web Server Gateway Interface) is a standard for Python web application servers to communicate with web frameworks. It ensures that Flask can run on different web servers like Gunicorn or Nginx.

Previous

python json handling

Next

flask routing

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.