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 and what does 'microframework' mean?
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,…
-
Most asked What is the application factory pattern in Flask and why use it?
An application factory is a create_app(config=None) function that creates and configures the Flask instance, initializes extensions and registers blueprints, instead of creating a global app at…
-
Most asked What are Blueprints in Flask?
Blueprints group related routes, templates, static files and error handlers into reusable components that are registered on an app (optionally with a URL prefix), so large apps can be organized by…
-
Most asked What request hooks does Flask provide and when do they run?
before_request runs before each view (returning a response short-circuits), after_request receives and can modify the response, teardown_request/teardown_appcontext always run at the end (even on…
-
Most asked What is WSGI and what role does Werkzeug play in Flask?
WSGI (PEP 3333) is the standard interface between Python web servers and apps: the app is a callable app(environ, start_response). Werkzeug is the WSGI toolkit Flask uses for request/response…
-
What are Flask signals and when would you use them?
Signals (via the Blinker library) let code subscribe to events like request_started, request_finished, got_request_exception or template_rendered, or to custom signals, decoupling side effects from…
-
What are class-based views (`View`, `MethodView`) in Flask?
MethodView maps HTTP methods to class methods (get, post, put, delete), making it convenient to group a REST resource's handlers. Register with add_url_rule('/items/int:id',…
-
What do `flask run --debug` and the reloader do, and why not use them in production?
Debug mode enables the interactive Werkzeug debugger and auto-reloader. The debugger allows executing arbitrary Python from the browser on error pages, so exposing it is equivalent to remote code…
-
What is an open redirect and how do you prevent it in a Flask login flow?
An open redirect happens when you redirect to a user-supplied URL (like ?next=https://evil.com), letting attackers abuse your domain in phishing. Only allow relative paths or an allow-list of hosts.
-
What notable changes came in Flask 2.x and 3.x?
Flask 2.0 added async views, route method shortcuts (@app.get) and nested blueprints; 2.2 added the JSON provider system and returning lists as JSON; 2.3/3.0 removed deprecated features like…
-
What is Flask-Admin and when is it appropriate?
Flask-Admin generates CRUD admin interfaces for SQLAlchemy (and other) models with minimal code, which is useful for internal back-office tools.
-
What's a good project structure for a medium-sized Flask app?
A package with an app factory (init.py), extensions.py, config.py, feature blueprints (each with routes, services, schemas, models), templates/ and static/, plus tests/ and a wsgi.py entry point.
-
What is Quart and how does it relate to Flask?
Quart is an ASGI reimplementation of the Flask API (now part of the Pallets project) where views, hooks and extensions can be async, enabling true async concurrency, WebSockets and HTTP/2 with…
-
What are `.env` and `.flaskenv` files used for?
When python-dotenv is installed, the flask CLI loads .flaskenv (public, committed settings like FLASK_APP) and .env (private local secrets, not committed) into environment variables.
-
What is a scoped session and how does Flask-SQLAlchemy manage it?
A scoped session gives each context (thread/greenlet, or Flask app context) its own Session object. Flask-SQLAlchemy scopes db.session to the app context and calls session.remove() at teardown so…
-
What is server-side template injection (SSTI) in Flask?
SSTI occurs when user input is used as part of a Jinja2 template source (e.g., render_template_string(f'Hello {name}')), letting attackers execute template expressions that can reach Python…
-
What are URL value preprocessors and defaults in Flask?
url_value_preprocessor extracts values from URL parameters before views run (e.g., a lang_code prefix into g), and url_defaults injects them automatically into url_for calls.
-
What is Flask's instance folder?
The instance folder (instance/ beside the package, or a configured path) holds deployment-specific files such as local config and SQLite databases that shouldn't be in version control; load from it…
-
What steps would you take to upgrade a legacy Flask 1.x app to Flask 3?
Upgrade Python first, then Flask/Werkzeug/Jinja2/extensions together, fix removed APIs (before_first_request, JSONEncoder, flask.escape, safe_join), adopt the JSON provider API and SQLAlchemy 2.0…
-
What is `app.add_url_rule()` and how does it relate to `@app.route`?
@app.route is a decorator wrapper around app.add_url_rule(rule, endpoint, view_func, options), which registers a URL rule directly. It's handy for class-based views or registering routes…
-
What are context processors and custom template filters in Flask?
A context processor (@app.context_processor) returns a dict of variables injected into every template; a custom filter (@app.template_filter('name')) adds a function usable as {{ value|name }}.
-
What arguments do teardown functions receive and what should they not do?
Teardown functions receive the unhandled exception (or None) that ended the request. They should release resources (close connections, remove sessions) and must not raise exceptions or depend on the…