Backend & APIs

Flask interview questions

Interviewers assess a candidate's grasp of Flask's minimalist design, its core components like routing, request handling, and templating, and their ability to build well-structured, maintainable, and secure web applications using its ecosystem.

15 questions (4 easy · 8 medium · 3 hard), each with what a strong answer covers and where people lose the point. Free to read, no account.

On this page (15 questions)

1.What does it mean for Flask to be a "microframework"? What are its implications?

Core

What a strong answer covers

  • Explain that Flask provides core WSGI utilities and routing but leaves choices for databases, ORMs, and other components to the developer.
  • Discuss the benefits like flexibility, less boilerplate, and suitability for APIs/smaller apps.
  • Mention the "batteries not included" philosophy, requiring developers to choose and integrate components.
  • Contrast with full-stack frameworks like Django, which offer more built-in features and opinions.

Where people lose the point

  • Not knowing what WSGI is or its relevance.
  • Failing to explain the "why" behind the microframework design (flexibility, choice).
  • Only stating it's "small" without elaborating on its architectural implications.
Link to this question

2.How do you define routes in Flask, and how can you handle different HTTP methods for the same URL?

Warm-up

What a strong answer covers

  • Describe the `@app.route()` decorator as the primary way to define routes.
  • Explain how to specify allowed HTTP methods using the `methods` argument (e.g., `methods=['GET', 'POST']`).
  • Provide an example of a view function handling both GET (to display a form) and POST (to process form submission) requests.
  • Mention using `request.method` inside the view function to differentiate logic based on the HTTP method.

Where people lose the point

  • Forgetting to import the `request` object when demonstrating method handling.
  • Not understanding the difference between `request.method` and the `methods` argument in `@app.route()`.
  • Providing an example that doesn't clearly separate GET and POST logic.
Link to this question

3.Explain the purpose of Flask's `request` object. How do you access form data, query parameters, and URL variables?

Core

What a strong answer covers

  • Define `request` as a global proxy object that holds all incoming request data for the current request.
  • Explain `request.form` for accessing data from POST requests (e.g., HTML form submissions).
  • Describe `request.args` for accessing query parameters from the URL (e.g., `?key=value`).
  • Explain how to access URL variables (dynamic parts of the URL path) by defining them in the route decorator (e.g., `<int:post_id>`) and receiving them as function arguments.

Where people lose the point

  • Confusing `request.form` with `request.args` or vice-versa.
  • Not understanding that `request` is a context-local proxy and only available within a request context.
  • Incorrectly trying to access URL variables via `request.args` or `request.form`.
Link to this question

4.What is `url_for()` in Flask, and why is it preferred over hardcoding URLs?

Warm-up

What a strong answer covers

  • Explain that `url_for()` is a function that generates a URL for a given view function.
  • Discuss its primary benefit: avoiding hardcoded URLs, which makes applications more robust to URL changes.
  • Mention that it correctly handles dynamic URL parts by taking keyword arguments corresponding to the route's variable components.
  • Provide an example demonstrating how `url_for()` is used and why it's better than a static string.

Where people lose the point

  • Not mentioning the robustness benefit against URL changes.
  • Incorrectly using `url_for()` with a string literal URL instead of a view function name.
  • Failing to explain how `url_for()` handles dynamic parameters.
Link to this question

5.Describe how Jinja2 templating works in Flask. How do you pass data from a Flask view to a Jinja2 template?

Warm-up

What a strong answer covers

  • Explain Jinja2 as Flask's default templating engine, allowing dynamic content generation in HTML.
  • Describe the `render_template()` function used in Flask view functions to load and render templates.
  • Show how to pass Python variables from the view function to the template using keyword arguments in `render_template()`.
  • Mention basic Jinja2 syntax for displaying variables (`{{ var }}`) and control flow (`{% if %}`, `{% for %}`).

Where people lose the point

  • Confusing Jinja2 syntax with standard Python syntax.
  • Not understanding the role of `render_template()` in bridging Python logic and HTML.
  • Failing to explain how variables passed to `render_template` become accessible in the template.
Link to this question

6.How do you implement template inheritance in Jinja2, and what are its advantages?

Core

What a strong answer covers

  • Explain the concept of a base template (`base.html`) that defines common page structure and `{% block %}` tags.
  • Describe how child templates use `{% extends 'base.html' %}` to inherit the base layout.
  • Explain how child templates can then override or append to specific blocks defined in the base template.
  • Discuss advantages such as code reuse, maintaining a consistent look and feel across the application, and easier maintenance.

Where people lose the point

  • Not understanding the `extends` and `block` relationship in Jinja2.
  • Creating redundant HTML across multiple templates instead of leveraging inheritance.
  • Failing to articulate the benefits of consistency and maintainability.
Link to this question

7.How do Flask sessions work? What is the role of `SECRET_KEY`?

Core

What a strong answer covers

  • Explain that Flask sessions are client-side by default, storing data in a cryptographically signed cookie on the user's browser.
  • Describe the `session` object as a dictionary-like interface to store user-specific data across requests.
  • Emphasize that the `SECRET_KEY` is crucial for cryptographic signing of the session cookie, preventing tampering and ensuring data integrity.
  • Clarify that the `SECRET_KEY` signs the data, but does not encrypt it by default, meaning session data is readable but not modifiable by the client.

Where people lose the point

  • Believing `SECRET_KEY` encrypts session data, rather than just signing it.
  • Not understanding that session data is stored on the client-side (in a cookie).
  • Forgetting to mention the importance of a strong, unique, and securely stored `SECRET_KEY`.
Link to this question

8.What are Flask Blueprints, and why are they useful for larger applications?

Core

What a strong answer covers

  • Define Blueprints as a way to organize related functionality into modular, reusable components within a Flask application.
  • Explain that blueprints can define their own routes, templates, static files, and error handlers, independent of the main application.
  • Discuss benefits such as improved code organization, better maintainability, and enhanced reusability of components across projects.
  • Provide a high-level example of how to create a blueprint and register it with the main Flask application instance.

Where people lose the point

  • Not understanding that blueprints are registered with the main app, not standalone applications.
  • Confusing blueprints with Python modules without explaining their specific Flask-related functionality.
  • Failing to articulate the benefits for application scalability and team collaboration.
Link to this question

9.Differentiate between Flask's application context and request context. When would you use each?

Hard

What a strong answer covers

  • Define the **application context** as making `current_app` available, pushed when the Flask application starts or for CLI commands.
  • Define the **request context** as making `request`, `session`, and `g` available, pushed for each incoming web request.
  • Explain that both contexts are necessary for Flask's global proxy objects to function correctly, as they provide access to context-specific data.
  • Discuss their lifecycle: application context can exist longer, while request context is tied to a single HTTP request.

Where people lose the point

  • Confusing the two contexts or their respective lifecycles.
  • Not understanding the concept of context locals and why they are needed for global proxies.
  • Incorrectly assuming `request` or `session` are always available outside of a request context.
Link to this question

10.How do you implement custom error pages (e.g., 404 Not Found, 500 Internal Server Error) in Flask?

Core

What a strong answer covers

  • Explain using the `@app.errorhandler()` decorator (or `blueprint.errorhandler()`) to register a function for specific HTTP status codes or exceptions.
  • Show how the error handler function takes the error object as an argument.
  • Demonstrate returning a rendered template along with the appropriate HTTP status code (e.g., `render_template('404.html'), 404`).
  • Discuss the importance of providing user-friendly and informative error pages.

Where people lose the point

  • Not returning the correct HTTP status code along with the error page.
  • Forgetting to register the error handler with `@app.errorhandler()` or `blueprint.errorhandler()`.
  • Only handling generic exceptions without specific HTTP status codes.
Link to this question

11.How does Flask serve static files (CSS, JavaScript, images)?

Warm-up

What a strong answer covers

  • Explain that Flask automatically serves files from a `static` folder located in the application's root directory by default.
  • Describe how to link to static files in Jinja2 templates using `url_for('static', filename='path/to/file.css')`.
  • Mention that `url_for('static', ...)` generates the correct URL path to the static asset.
  • Briefly note that for production deployments, it's common practice to use a dedicated web server (like Nginx or Apache) to serve static files directly for performance.

Where people lose the point

  • Hardcoding static file paths in templates instead of using `url_for('static', ...)`.
  • Not understanding the default `static` folder convention.
  • Confusing Flask's static file serving with a production-grade static file server.
Link to this question

12.What is WSGI, and how does it relate to running a Flask application in production?

Core

What a strong answer covers

  • Define WSGI (Web Server Gateway Interface) as a standard Python interface between web servers (e.g., Nginx, Apache) and Python web applications.
  • Explain that Flask applications are WSGI-compliant, meaning they adhere to this standard.
  • Discuss how a WSGI server (like Gunicorn or uWSGI) acts as an intermediary, receiving requests from a front-end web server and passing them to the Flask application.
  • Emphasize that Flask's built-in development server is not suitable for production, and a WSGI server is required for robust, scalable deployment.

Where people lose the point

  • Confusing Flask itself with a WSGI server.
  • Not understanding the role of a front-end web server (Nginx/Apache) in conjunction with a WSGI server.
  • Suggesting Flask's development server is adequate for production.
Link to this question

13.How do Flask extensions simplify development? Give an example of a common Flask extension and its use.

Core

What a strong answer covers

  • Explain that Flask extensions are separate Python packages that provide pre-built integrations for common web development tasks.
  • Discuss how they simplify development by reducing boilerplate code, promoting best practices, and offering robust solutions for complex features.
  • Provide Flask-WTF as an example: it simplifies form creation, validation, and CSRF protection by integrating WTForms.
  • Briefly mention other examples like Flask-SQLAlchemy (database ORM) or Flask-Login (user session management).

Where people lose the point

  • Not understanding that extensions are separate, installable packages.
  • Describing a core Flask feature as an extension.
  • Failing to explain *how* an extension simplifies a specific task.
Link to this question

14.What is the `g` object in Flask, and when would you use it?

Hard

What a strong answer covers

  • Explain `g` as a global object (short for "global") that is specific to the current request context.
  • Describe its purpose: to store data that needs to be accessed by multiple functions or parts of the application during a single request.
  • Provide concrete examples of its use, such as storing a database connection, the current authenticated user object, or other request-specific resources.
  • Emphasize that its lifecycle is tied to the request context, meaning data stored in `g` is cleared after the request ends.

Where people lose the point

  • Confusing `g` with the `session` object (which persists across requests).
  • Using `g` to store application-wide data instead of data specific to the current request.
  • Not understanding that `g` is a context-local proxy.
Link to this question

15.Briefly describe how you would approach testing a Flask application.

Hard

What a strong answer covers

  • Mention Flask's built-in `app.test_client()` for making simulated HTTP requests to the application without running a live server.
  • Explain how to set up a testing environment, often using an in-memory database (e.g., SQLite) to ensure tests are isolated and fast.
  • Discuss testing view functions, route responses (status codes, content), and interactions with the database.
  • Suggest using a testing framework like `pytest` or `unittest` for structuring tests and assertions.

Where people lose the point

  • Not knowing about `app.test_client()` as the primary tool for integration testing Flask apps.
  • Focusing only on unit testing helper functions rather than the web interaction.
  • Failing to mention the importance of an isolated test database.
Link to this question
No account needed

Answer one real Flask question now

A question a Flask panel actually asks, answered out loud, scored on what you said and how you said it. Under two minutes, and nothing to sign up for.

What does it mean for Flask to be a "microframework"? What are its implications?

We never store the audio. Your answer is deleted within 24 hours unless you save the result.

How Flask answers get judged

The weights a Flask interviewer is holding, whether or not they say so out loud. Round Zero scores your practice answers against exactly these, and quotes your own words back as the evidence for each.

Correctness & Technical Accuracy

35%

The answer demonstrates a precise and accurate understanding of Flask concepts, syntax, and best practices. No factual errors or misunderstandings of core mechanisms.

Conceptual Depth

30%

The candidate explains not just *what* but *why* certain Flask features exist or are used, demonstrating a deep grasp of underlying principles (e.g., microframework philosophy, context locals, WSGI).

Problem-Solving & Design

20%

The answer reflects an ability to apply Flask concepts to solve common web development problems, including considerations for application structure, scalability, and security.

Communication & Clarity

15%

The explanation is clear, concise, well-structured, and easy to understand. Technical terms are used appropriately, and examples (if provided) are relevant and illustrative.

Related Backend & APIs skills

All skills →

Now say them out loud

You have read what strong Flask answers contain. The next thing that moves the needle is producing one under time, out loud, and finding out where it falls apart.

  • These questions asked back, with follow-ups
  • Flashcards for the ones you keep missing
  • A scored mock that quotes your own answers

Browse every skill

Practising Flask: common questions

What Flask interview questions should I practice?
Start with the core areas Flask interviewers probe: What does it mean for Flask to be a "microframework"? What are its implications; How do you define routes in Flask, and how can you handle different HTTP methods for the same URL; Explain the purpose of Flask's `request` object. How do you access form data, query parameters, and URL variables. This page outlines strong answers and common mistakes, and the scored path drills each one with follow-ups.
Is the Flask practice free?
Yes. The Flask path runs free inside Round Zero: lessons, practice questions and flashcards. Drills are unlimited on every plan, free included. So is the full scorecard. Free also covers 3 complete scored interviews, no card.
How is this different from a Flask question list?
A static list gives you questions with no feedback. Round Zero runs a live scored practice that probes your actual answers, rotates difficulty, and tells you exactly what to fix, grounded in a Flask rubric.
How should I prepare for a Flask interview?
Learn the concepts, drill the questions until answers come fast, then prove it in a scored mock. Round Zero sequences all three so you know you are ready, not just that you read about Flask.
How is a Flask answer scored?
Flask answers are scored on correctness & technical accuracy, conceptual depth, problem-solving & design, communication & clarity, with evidence quoted from what you actually said, so feedback is specific instead of generic praise.