Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a FastAPI app instance.
FastAPI
from fastapi import [1] app = [1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Flask or Django classes instead of FastAPI.
Forgetting to instantiate the app.
✗ Incorrect
FastAPI apps are created by instantiating the FastAPI class.
2fill in blank
mediumComplete the code to define a route in Flask.
FastAPI
from flask import Flask app = Flask(__name__) @app.route([1]) def home(): return "Hello from Flask!"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-root path when the question asks for the main route.
Forgetting quotes around the route string.
✗ Incorrect
In Flask, the root route is defined with "/".
3fill in blank
hardFix the error in this Django view function to return a simple HTTP response.
FastAPI
from django.http import HttpResponse def home(request): return [1]("Hello from Django!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
render without a template.Returning a string directly instead of an HttpResponse.
✗ Incorrect
Django views return an HttpResponse object to send text responses.
4fill in blank
hardFill both blanks to create a FastAPI GET endpoint that returns a greeting.
FastAPI
from fastapi import FastAPI app = FastAPI() @app.[1]("/greet") def greet(): return [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
post decorator for a GET endpoint.Returning a plain string instead of a dictionary for JSON.
✗ Incorrect
FastAPI uses @app.get to define GET routes and returns JSON by default.
5fill in blank
hardFill all three blanks to create a Django URL pattern for the home view.
FastAPI
from django.urls import path from .views import home urlpatterns = [ path([1], [2], name=[3]) ]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
"/" instead of empty string for root path.Not quoting the route name string.
✗ Incorrect
Django URL patterns use an empty string "" for the root path, the view function name, and a string name for the route.