Flask interview question · Most asked
What is Flask and what does 'microframework' mean?
Summary
Flask is a lightweight WSGI web framework for Python built on Werkzeug (HTTP/WSGI toolkit) and Jinja2 (templating). 'Micro' means the core stays small and unopinionated, with features like ORM, forms and auth added via extensions.
Longer Answer
Flask gives you routing, request/response objects, sessions, templating, a CLI and a test client. It doesn't choose a database layer, validation library or project structure for you. That flexibility suits APIs, small services and teams that want control, but larger apps need deliberate conventions (blueprints, app factory, extensions).
Code Example
from flask import Flask, jsonify
app = Flask(__name__)
@app.get("/health")
def health():
return jsonify(status="ok")
# flask --app app run --debug
Key Points
- Built on Werkzeug + Jinja2 (+ Click, ItsDangerous)
- Small core, extensible via extensions
- No built-in ORM or form validation
- WSGI-based; async views supported with limits
Comparison / Tradeoffs
| Flask | Django | FastAPI | |
|---|---|---|---|
| Philosophy | Micro, choose your stack | Batteries included | API-first, type hints |
| Interface | WSGI | WSGI/ASGI | ASGI |
| ORM | Bring your own (SQLAlchemy) | Django ORM | Bring your own |
More most-asked Flask questions
- How do Flask sessions work and what are their security implications?
- How do you use SQLAlchemy with Flask (Flask-SQLAlchemy 3.x)?
- What are Blueprints in Flask?
- Explain Flask's application context and request context.
- What is the application factory pattern in Flask and why use it?
- How does routing work in Flask, including variable rules and HTTP methods?
- How do you access request data and build responses in Flask?
- How do you implement user authentication in Flask?