Bird
0
0

Which FastAPI method is used to add static file serving to the app?

easy🧠 Conceptual Q2 of 15
FastAPI - File Handling
Which FastAPI method is used to add static file serving to the app?
Aapp.include_router()
Bapp.mount()
Capp.add_static()
Dapp.static_files()
Step-by-Step Solution
Solution:
  1. Step 1: Identify method to attach static files

    FastAPI uses app.mount() to attach a static files directory to a URL path.
  2. Step 2: Understand other methods

    include_router() adds routers, but not static files. add_static() and static_files() are not valid FastAPI methods.
  3. Final Answer:

    app.mount() -> Option B
  4. Quick Check:

    Mount static files = app.mount() [OK]
Quick Trick: Use app.mount() to serve static files in FastAPI [OK]
Common Mistakes:
MISTAKES
  • Using include_router() for static files
  • Assuming add_static() or static_files() exist
  • Not mounting static files at all

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes