Complete the code to import the TrustedHostMiddleware from FastAPI.
from fastapi.middleware.[1] import TrustedHostMiddleware
The correct import path uses underscores: trusted_host.
Complete the code to add TrustedHostMiddleware to the FastAPI app with allowed hosts.
app.add_middleware(TrustedHostMiddleware, allowed_hosts=[1])Allowed hosts should be a list of specific hostnames without wildcards for security.
Fix the error in the middleware setup by completing the code correctly.
app = FastAPI() app.add_middleware([1], allowed_hosts=['myapp.com'])
The middleware class name is TrustedHostMiddleware with exact casing.
Fill both blanks to create a FastAPI app and add TrustedHostMiddleware with allowed hosts.
app = [1]() app.add_middleware([2], allowed_hosts=['api.example.com'])
The app is created with FastAPI() and middleware class is TrustedHostMiddleware.
Fill all three blanks to define a FastAPI app, add TrustedHostMiddleware, and specify allowed hosts.
from fastapi import [1] from fastapi.middleware.trusted_host import [2] app = [3]() app.add_middleware(TrustedHostMiddleware, allowed_hosts=['localhost', 'mydomain.com'])
Import FastAPI and TrustedHostMiddleware with correct casing, then create app with FastAPI().