'List files from a static folder in FastAPI

I know how to serve static files in FastAPI using StaticFiles, how can I enable directory listing like in Apache web server?

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

app = FastAPI(...)

app.mount("/samples", StaticFiles(directory='samples'), name="samples")

# GET http://localhost:8000/samples/path/to/file.jpg -> OK
# GET http://localhost:8000/samples -> not found error


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source