Bird
Raised Fist0
FastAPIframework~20 mins

FastAPI vs Flask vs Django comparison - Practice Questions

Choose your learning style10 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.

Practice

(1/5)
1. Which framework is best known for being modern, fast, and supporting automatic type checking for APIs?
easy
A. Flask
B. Pyramid
C. Django
D. FastAPI

Solution

  1. Step 1: Understand framework features

    FastAPI is designed to be modern and fast, with built-in support for Python type hints to validate and document APIs automatically.
  2. Step 2: Compare with other frameworks

    Flask is minimal and easy to start but lacks built-in type checking. Django is full-featured but more heavyweight and not focused on type checking.
  3. Final Answer:

    FastAPI -> Option D
  4. Quick Check:

    Modern + fast + type checking = FastAPI [OK]
Hint: Modern + fast + type hints = FastAPI [OK]
Common Mistakes:
  • Confusing Flask's simplicity with FastAPI's speed
  • Thinking Django has built-in type checking
  • Choosing Pyramid which is less common
2. Which of the following is the correct way to create a simple route in Flask?
easy
A. app.route('/')(def home(): return 'Hello')
B. @app.route('/') def home(): return 'Hello'
C. app.get('/') def home(): return 'Hello'
D. @app.get('/') def home(): return 'Hello'

Solution

  1. Step 1: Recall Flask route syntax

    In Flask, routes are created using the @app.route decorator above a function.
  2. Step 2: Identify correct decorator and syntax

    @app.route('/') def home(): return 'Hello' uses @app.route('/') with proper Python function definition and indentation, which is correct Flask syntax.
  3. Final Answer:

    @app.route('/') def home(): return 'Hello' -> Option B
  4. Quick Check:

    Flask route decorator = @app.route [OK]
Hint: Flask uses @app.route decorator, not app.route() call [OK]
Common Mistakes:
  • Missing @ symbol before decorator
  • Using app.get instead of app.route in Flask
  • Incorrect indentation or function syntax
3. Given this FastAPI code snippet, what will be the output when accessing /items/5?
from fastapi import FastAPI
app = FastAPI()

@app.get('/items/{item_id}')
async def read_item(item_id: int):
    return {'item_id': item_id * 2}
medium
A. {'item_id': 10}
B. {'item_id': '5'}
C. {'item_id': 5}
D. Error: item_id must be a string

Solution

  1. Step 1: Understand path parameter and type

    The route expects an integer item_id. When accessing /items/5, item_id is 5 as int.
  2. Step 2: Calculate returned value

    The function returns a dictionary with 'item_id' key and value item_id * 2, so 5 * 2 = 10.
  3. Final Answer:

    {'item_id': 10} -> Option A
  4. Quick Check:

    5 * 2 = 10 output [OK]
Hint: Multiply path param by 2 as int to get output [OK]
Common Mistakes:
  • Assuming item_id is string, not int
  • Returning original item_id instead of multiplied
  • Expecting error due to type mismatch
4. Identify the error in this Django view code snippet:
from django.http import HttpResponse

def home(request):
return HttpResponse('Hello')
medium
A. Indentation error in function body
B. HttpResponse should be replaced with JsonResponse
C. Missing import for HttpRequest
D. Function name must be capitalized

Solution

  1. Step 1: Check Python syntax rules

    Python requires the function body to be indented under the def line.
  2. Step 2: Identify indentation problem

    The return statement is not indented, causing a syntax error.
  3. Final Answer:

    Indentation error in function body -> Option A
  4. Quick Check:

    Python function body must be indented [OK]
Hint: Check indentation under def for Python functions [OK]
Common Mistakes:
  • Ignoring indentation errors
  • Thinking import is missing
  • Assuming JsonResponse is mandatory
5. You want to build a large, complex web app with built-in admin, user authentication, and database ORM. Which framework is the best choice and why?
hard
A. FastAPI, because it is the fastest and has built-in admin
B. Flask, because it is minimal and easy to add features manually
C. Django, because it is full-featured with admin, auth, and ORM included
D. FastAPI, because it supports async and type checking

Solution

  1. Step 1: Identify requirements for large complex app

    Needs built-in admin panel, user authentication, and ORM for database management.
  2. Step 2: Match framework features to requirements

    Django provides all these features out of the box, making it ideal for large apps. FastAPI and Flask require extra setup for these.
  3. Final Answer:

    Django, because it is full-featured with admin, auth, and ORM included -> Option C
  4. Quick Check:

    Full features for big apps = Django [OK]
Hint: Full features + admin + auth = Django [OK]
Common Mistakes:
  • Choosing FastAPI for admin features it lacks
  • Thinking Flask has built-in admin
  • Ignoring Django's batteries-included approach
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard