PrepPilotPractise free

Python Web (FastAPI, Django, Flask) interview questions

Frameworks, ORM, validation, auth and deployment

17 questions · FastAPI · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What is the main difference between Flask and Django?

Django is a full-stack framework with built-in ORM, authentication, and admin, while Flask is a lightweight microframework that gives you more flexibility but requires you to add extensions for things like database access.

How does FastAPI validate incoming request data?

FastAPI uses Pydantic models and Python type hints to automatically validate and parse incoming request data, raising clear errors if the data doesn't match the expected schema.

What is the purpose of Django migrations?

Migrations in Django track and apply changes to the database schema, ensuring that the database stays in sync with the models defined in code.

How do you define a route in Flask?

You use the @app.route() decorator to map a URL path to a Python function, which handles the request and returns a response.

Intermediate questions

When would you choose FastAPI over Django?

I'd choose FastAPI when I need high-performance async APIs, automatic OpenAPI docs, or tight control over validation and serialization. Django is better for projects needing a full-featured admin, built-in authentication, and rapid prototyping of complex apps.

Explain how dependency injection works in FastAPI.

FastAPI lets you declare dependencies using the Depends function, which can inject things like database sessions or authentication checks into your endpoint functions. This makes code more modular and testable, since dependencies are explicit and easy to override in tests.

What is the N+1 query problem and how do you avoid it in Django?

The N+1 problem happens when an ORM issues one query for a list of objects and then an additional query for each object's related data. In Django, I use select_related for foreign keys and prefetch_related for many-to-many or reverse relationships to fetch related data in fewer queries.

How does Django's admin interface work?

Django's admin auto-generates CRUD interfaces for registered models, letting you manage database records through a web UI. You can customize the admin by registering models and configuring their display and permissions.

What is the difference between session authentication and JWT?

Session authentication stores user state on the server and uses a cookie to track the session. JWT is stateless; the server issues a signed token that the client sends with each request, and the server validates the token without storing session data.

How do you run a Django app in production?

I run Django behind a WSGI server like Gunicorn, often inside a Docker container, and serve static files with a reverse proxy like Nginx. I also set environment variables for settings like DEBUG and database credentials.

How do you test a FastAPI endpoint with pytest?

I use FastAPI's TestClient to simulate HTTP requests in tests. With pytest, I often define a fixture that returns a TestClient instance, then write tests that call endpoints and assert on the responses.

What is the role of middleware in Django?

Middleware in Django are hooks that process requests and responses globally. They're used for things like authentication, logging, and modifying requests or responses before they reach the view or after the response is generated.

Senior questions

Describe how you would deploy a FastAPI app for high concurrency.

See the answer in the app, free

How would you debug a slow Django API endpoint?

See the answer in the app, free

What are the trade-offs between WSGI and ASGI for Python web apps?

See the answer in the app, free

How would you structure tests for a large Django or FastAPI project?

See the answer in the app, free

How do you ensure secure authentication in a containerized Python web app?

See the answer in the app, free

More Python topics