Home › Blog › Flask Interview Questions (2026): 30 Questions on Contexts, Blueprints and Deployment

Flask Interview Questions (2026): 30 Questions on Contexts, Blueprints and Deployment

Flask interview questions test what a micro-framework leaves to you: WSGI, the application factory, blueprints, the application and request contexts, sessions, extensions, testing and production deployment. Interviewers want to hear that you know which parts Flask gives you and which you must choose.

Flask interview questions test what a micro-framework leaves to you: WSGI, the application factory, blueprints, the application and request contexts, sessions, extensions, testing and production deployment. Interviewers want to hear that you know which parts Flask gives you and which you must choose. As of November 17, 2026, PyPI lists Flask 3.1.3 (released February 18, 2026, per Flask's changelog) as the current version. The changelog's unreleased 3.2.0 entry merges RequestContext into AppContext, drops Python 3.9 and 3.10, and makes redirect() return 303 by default, so ask which version a team runs.

Below are 30 questions by level, five debugging scenarios and how Python web interviews test this. Language fundamentals are in Python interview questions; the two usual comparisons are Django and FastAPI.

Flask interview questions: fundamentals (1–10)

  1. What is Flask? A lightweight WSGI web framework built on Werkzeug (the WSGI toolkit) and Jinja (templates). The core handles routing, requests, responses and sessions; databases, forms and auth come from extensions or your own code.
  2. Write a minimal Flask app. app = Flask(__name__), then @app.get("/") on a function returning a string, and run it with flask --app app run --debug.
  3. What is WSGI? The standard interface between Python web servers and applications (PEP 3333). A Flask app is a WSGI callable, served in production by Gunicorn, uWSGI, Waitress or mod_wsgi.
  4. How do routes and converters work? @app.route("/users/<int:user_id>", methods=["GET", "POST"]) passes user_id as an int. Built-in converters are string, int, float, path and uuid.
  5. Why url_for? url_for("profile", username="ada") builds a URL from the endpoint name, so routes can change without breaking links, and it handles escaping and blueprint prefixes.
  6. What does the request object hold? request.args (query string), request.form, request.get_json(), request.files, request.headers and request.cookies, through a context-local proxy.
  7. What can a view return? A string, a dict or list (converted to JSON), a tuple of body, status and headers, or a Response object; jsonify is the explicit JSON helper.
  8. How do templates stay safe? render_template uses Jinja with autoescaping on for HTML templates, so user input is escaped. Marking content |safe or wrapping it in Markup turns that off and can open XSS.
  9. How does the default session work? It is a cookie signed with SECRET_KEY: the client can read it but not change it undetected. Never store secrets in it; use a server-side session extension for large or sensitive data. Flask 3.1 added SECRET_KEY_FALLBACKS for key rotation.
  10. What does debug mode do? flask run --debug enables the reloader and an interactive in-browser debugger that can run arbitrary code, so it must never be on in production. The built-in server is for development only.

Intermediate Flask questions (11–20)

  1. What is the application factory pattern? A create_app(config=None) function that builds the app, loads config, calls init_app(app) on extensions and registers blueprints. It allows several configurations (tests, production) and avoids circular imports.
  2. What are blueprints? Modules of routes, templates, static files and handlers registered on an app, often with a url_prefix. They organize a large app; they are not separate apps.
  3. Application context versus request context? The application context provides current_app and g; the request context provides request and session. Flask pushes both for each request. Scripts, CLI commands and background jobs push one with with app.app_context():. Flask's unreleased 3.2 merges the two.
  4. What is g? A namespace for data during one application context, such as a database connection opened for the request. It is reset every request; it is not for data shared across requests.
  5. How are context locals safe with concurrent requests? request, session and g are proxies backed by Python's contextvars, so each worker thread, greenlet or task sees its own values.
  6. What request hooks exist? before_request (return a response to short-circuit, as for auth checks), after_request (modify the response) and teardown_request or teardown_appcontext (cleanup that runs even after errors).
  7. How do you handle errors? @app.errorhandler(404) or an exception class, abort(403) inside views, and JSON error bodies for APIs. Blueprints can register their own handlers.
  8. How do you manage configuration? app.config is a dict loaded with from_object, from_file or from_prefixed_env() (reads FLASK_-prefixed variables). Keep secrets in environment variables and machine-specific files in the instance folder.
  9. How do you add a database? Usually Flask-SQLAlchemy (db = SQLAlchemy(), then db.init_app(app) in the factory) with Flask-Migrate for Alembic migrations. Sessions are tied to the application context and cleaned up at teardown.
  10. How do you test a Flask app? Create the app with create_app({"TESTING": True}) in a pytest fixture, call routes through app.test_client(), test CLI commands with app.test_cli_runner(), and use app.test_request_context() for functions that need a request.

Experienced and senior Flask questions (21–30)

  1. How do you deploy Flask to production? A WSGI server such as Gunicorn (gunicorn -w 4 'app:create_app()') or Waitress, behind a reverse proxy that terminates TLS and serves static files. Wrap the app in Werkzeug's ProxyFix so it trusts the proxy's forwarded headers.
  2. Does Flask support async views? Yes, async def views work when installed with flask[async], but Flask stays a WSGI app: each request still holds a worker. For many concurrent slow I/O calls, an ASGI framework such as FastAPI or Quart fits better.
  3. What are the main security settings? A strong SECRET_KEY; CSRF protection for forms (Flask-WTF); SESSION_COOKIE_SECURE, HTTPONLY and SAMESITE; MAX_CONTENT_LENGTH plus 3.1's MAX_FORM_MEMORY_SIZE and MAX_FORM_PARTS; secure_filename for uploads; and 3.1's TRUSTED_HOSTS.
  4. How do you handle authentication? Session login with Flask-Login (login_user, @login_required, a user loader) for web apps, or token auth such as JWT for APIs. Hash passwords with werkzeug.security.generate_password_hash.
  5. How do you structure a REST API? Blueprints per resource, MethodView class-based views or route functions, schema validation (marshmallow or Pydantic), consistent JSON errors and pagination.
  6. Where do long-running tasks go? Not in the request. Hand them to a task queue such as Celery or RQ with a broker, and push an application context inside the worker when it needs app config or the database.
  7. How do you stream a response? Return a generator, wrapped in stream_with_context if it needs the request: Response(stream_with_context(gen()), mimetype="text/event-stream").
  8. What are signals? Blinker-based notifications such as request_started and template_rendered for decoupled hooks like metrics. Flask 3.1 requires Blinker 1.9 or later.
  9. Why can't you keep state in a global variable? Production runs several worker processes, each with its own memory, and restarts them. Shared state belongs in a database, Redis or the session.
  10. Flask, Django or FastAPI? Flask: minimal and flexible, you assemble the stack. Django: batteries included (ORM, admin, auth). FastAPI: ASGI and async with Pydantic validation and automatic OpenAPI. Pick by project size, team and concurrency needs.

Flask scenario and troubleshooting questions

RuntimeError: working outside of application context. Code that uses current_app or the database runs outside a request, such as a script, a thread or a Celery task. Wrap it in with app.app_context():.

Users are logged out after every deploy. SECRET_KEY is generated at startup, so old session cookies no longer verify. Load a stable key from the environment, and list old keys in SECRET_KEY_FALLBACKS when rotating.

Fast locally, slow under real traffic. Probably the development server or one synchronous Gunicorn worker blocked on slow I/O. Add workers or threads, move slow work to a queue, and check database connection pooling.

url_for builds http:// links behind an HTTPS load balancer. The app does not trust forwarded headers. Add ProxyFix with the right number of proxies, or set PREFERRED_URL_SCHEME for URLs built outside a request.

Circular imports between app.py and models.py. Create extensions without an app (db = SQLAlchemy()) in their own module, then bind them in create_app with init_app.

How Flask interviews test this

FormatWhat it usually looks likeHow to prepare
Concept Q&AContexts, blueprints, the factory pattern, sessions, debug modeExplain each with one code line
Build exerciseA small CRUD API with validation, errors and testsBuild one from scratch; see REST API interview questions for the design side
Code reviewFind the security issue (debug on, weak key, unescaped template) or a context errorRead the security and deployment answers above
Senior or system designScaling Flask, background jobs, auth, observabilityKnow how workers, proxies and queues fit together

Where CoPilot Interview fits

CoPilot Interview is an AI interview assistant. Its free AI mock interview builds Flask and Python questions from your résumé and the job description, reads them aloud and scores each spoken answer out of 10, which is a fast way to find the answers above that you know but cannot yet explain cleanly under pressure. The browser demo has 145 practice questions in 10 tracks, scores typed answers out of 10 and needs no signup. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. Paid plans are Standard at $24.99 a month and Pro at $39.99 a month, in the desktop app for Windows 10/11 and macOS 12 or later.

Use it to practice. Online assessments, proctored tests, take-home tasks with rules and AI-led rounds forbid outside help, so prepare for those instead of bringing a tool. For any live interview, follow your employer's rules.

Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.

Frequently asked questions

What are the most common Flask interview questions?

Application versus request context, the application factory, blueprints, how sessions work, url_for, request hooks, error handlers, testing with the test client, and production deployment with a WSGI server.

Is Flask still worth learning in 2026?

Yes. It is actively maintained (3.1.3 is current as of November 17, 2026) and widely used for APIs, internal tools and ML model serving; its concepts transfer to other Python frameworks.

Is Flask asynchronous?

Flask supports async def views, but it is a WSGI framework, so each request still occupies a worker. For heavy async workloads, teams choose an ASGI framework.

What is the difference between Flask and Django?

Flask is a minimal core you extend with chosen libraries; Django ships an ORM, admin, auth and conventions out of the box.

How do I prepare for a Flask interview?

Build a small app with an application factory, two blueprints, a database extension and pytest tests, deploy it behind Gunicorn, and explain each choice out loud.

Practice this interview before the real one

The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.

Start a mock interview