0
0
FastAPIframework~20 mins

FastAPI vs Flask vs Django comparison - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FastAPI Mastery Challenge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does FastAPI handle request validation compared to Flask and Django?
Consider how each framework processes incoming data and validates it automatically or manually. Which statement best describes FastAPI's approach?
AFastAPI requires manual validation of request data similar to Flask, while Django automatically validates using Python type hints.
BFlask automatically validates request data using decorators, FastAPI requires manual validation, and Django does not support validation.
CDjango uses Python type hints for validation, Flask uses forms, and FastAPI does not validate request data.
DFastAPI uses Python type hints to automatically validate and convert request data, unlike Flask which requires manual validation and Django which uses forms or serializers.
Attempts:
2 left
💡 Hint
Think about how FastAPI leverages modern Python features to reduce boilerplate.
📝 Syntax
intermediate
2:00remaining
Which code snippet correctly creates a simple GET endpoint in FastAPI?
Select the code that defines a GET endpoint at path '/' returning JSON {'message': 'Hello'} in FastAPI.
A
from fastapi import FastAPI
app = FastAPI()

@app.get('/')
async def root():
    return {'message': 'Hello'}
B
from flask import Flask
app = Flask(__name__)

@app.route('/')
def root():
    return {'message': 'Hello'}
C
from django.http import JsonResponse

def root(request):
    return JsonResponse({'message': 'Hello'})
D
import fastapi
app = fastapi.FastAPI()

@app.post('/')
def root():
    return {'message': 'Hello'}
Attempts:
2 left
💡 Hint
Look for the FastAPI decorator for GET and async function.
lifecycle
advanced
2:30remaining
What happens when you add a middleware in FastAPI compared to Flask and Django?
Which statement best describes middleware behavior differences among FastAPI, Flask, and Django?
AFastAPI middleware runs before and after each request asynchronously, Flask middleware runs synchronously, and Django middleware runs synchronously but supports hooks at multiple points.
BDjango middleware runs only after the response, FastAPI middleware runs only before the request, Flask middleware runs both before and after synchronously.
CFlask middleware runs asynchronously, FastAPI middleware runs synchronously, and Django middleware does not exist.
DAll three frameworks run middleware only after the response is generated.
Attempts:
2 left
💡 Hint
Consider async support and lifecycle hooks in each framework.
🔧 Debug
advanced
2:30remaining
Why does this FastAPI code raise a validation error but similar Flask code does not?
Given this FastAPI endpoint: from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class Item(BaseModel): name: str price: float @app.post('/items/') async def create_item(item: Item): return item Why would sending {'name': 'Book', 'price': 'free'} cause an error in FastAPI but not in Flask?
AFlask raises a validation error too, but it is silent and does not stop execution.
BFlask automatically converts 'price' to float, but FastAPI does not support type conversion.
CFastAPI uses Pydantic to enforce type validation and rejects 'price' as a string, while Flask does not validate types automatically.
DFastAPI requires all fields to be strings, so 'price' as float causes error, Flask accepts any type.
Attempts:
2 left
💡 Hint
Think about how FastAPI uses Pydantic models for input validation.
🧠 Conceptual
expert
3:00remaining
Which framework is best suited for building a high-performance asynchronous API with automatic docs and why?
Choose the framework that naturally supports asynchronous programming, automatic interactive API documentation, and modern Python features.
AFlask, because it has built-in async support and automatic API documentation generation.
BFastAPI, because it is built on ASGI, supports async/await natively, and generates OpenAPI docs automatically.
CDjango, because it is the oldest and most stable framework with async support and automatic docs.
DNone of these frameworks support asynchronous programming or automatic docs.
Attempts:
2 left
💡 Hint
Consider which framework was designed with async and docs in mind from the start.