Interview Q&A · questions with model answers
Flask Interview Questions
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked What is `flask.g` and when should you use it?
g is a namespace object scoped to the application context (effectively per request) for storing data during a request, such as the current user or a lazily created DB connection.
-
Most asked When would you choose Flask over FastAPI or Django?
Choose Flask for server-rendered or mixed apps where you want a small, flexible core and a mature ecosystem; FastAPI for typed, async-first JSON APIs with automatic OpenAPI; Django when you want an…
-
Which security measures should a production Flask app have?
Strong secret key, debug off, secure cookie flags, CSRF protection for forms, autoescaped templates, parameterized queries (SQLAlchemy), security headers (HSTS, CSP; e.g., via Flask-Talisman), rate…
-
When would you use gevent workers with Flask, and what are the caveats?
gevent workers (gunicorn -k gevent) handle many concurrent I/O-bound requests per process using greenlets and monkey-patched blocking I/O, which suits apps that mostly wait on network calls.
-
How do you return dataclasses or ORM objects as JSON in Flask?
Flask's default JSON provider serializes dataclasses automatically; ORM objects need explicit conversion via a to_dict() method or a schema (marshmallow/Pydantic) that controls exposed fields.
-
What's the difference between returning a dict and `jsonify()` in Flask?
Since Flask 1.1 (dicts) and 2.2 (lists), returning a dict or list from a view is automatically converted with jsonify, so both produce a JSON response with application/json. jsonify is still useful…
-
What's the difference between `request.args`, `request.form`, `request.values` and `request.get_json()`?
args holds URL query parameters, form holds form-encoded or multipart fields, values combines args and form, and get_json() parses a JSON body (it raises a 415 error if the content type isn't JSON,…