在简化的情况下,我们有一个项目和文件。文件属于项目。他们每个人都有自己的路由器来通过 API 执行 CRUD 操作。
因此,在代码中它应该如下所示:
from fastapi import FastAPI, APIRouter
app = FastAPI()
projects_router = APIRouter()
files_router = APIRouter()
app.include_router(projects_router, prefix="/projects")
projects_router.include_router(files_router, prefix="/{project_id}/files")
@files_router.get("/")
def list_files(project_id: int):
# Some code, that list all project's files by project_id
但是“list_files”函数无法获取project_id。
怎么做?