0
0
FastAPIframework~10 mins

Serving static files in FastAPI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the class needed to serve static files in FastAPI.

FastAPI
from fastapi.staticfiles import [1]
Drag options to blanks, or click blank then click option'
AStaticFiles
BFileResponse
CStaticPath
DFileStatic
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing FileResponse which is for sending single files, not mounting static directories.
Using StaticPath which does not exist.
2fill in blank
medium

Complete the code to mount the static files directory at the URL path '/static'.

FastAPI
app.mount("/static", [1](directory="static"), name="static")
Drag options to blanks, or click blank then click option'
AStaticFiles
BFileResponse
CStaticPath
DFileStatic
Attempts:
3 left
💡 Hint
Common Mistakes
Using FileResponse which is for single files, not directories.
Using a non-existent class like StaticPath.
3fill in blank
hard

Fix the error in the code to correctly serve static files from the 'assets' folder at '/assets'.

FastAPI
app.mount("/assets", StaticFiles(directory=[1]), name="assets")
Drag options to blanks, or click blank then click option'
Aassets
Bstatic
C"assets"
D"static"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong folder name.
Not using quotes around the folder name string.
4fill in blank
hard

Fill both blanks to create a FastAPI app that serves static files from 'public' at '/public'.

FastAPI
from fastapi import FastAPI
from fastapi.staticfiles import [1]

app = [2]()
app.mount("/public", StaticFiles(directory="public"), name="public")
Drag options to blanks, or click blank then click option'
AStaticFiles
BFastAPI
CApp
DStaticPath
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class names like StaticPath or App.
Not calling FastAPI as a function.
5fill in blank
hard

Fill all three blanks to serve static files from 'assets' at '/assets' with a FastAPI app.

FastAPI
from fastapi import [1]
from fastapi.staticfiles import [2]

app = [3]()
app.mount("/assets", StaticFiles(directory="assets"), name="assets")
Drag options to blanks, or click blank then click option'
AFastAPI
BStaticFiles
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up import names.
Not calling FastAPI as a function.