【发布时间】:2021-07-22 13:50:27
【问题描述】:
我正在尝试在 fastapi 服务器中为我的路由添加验证,按照说明 here 并设法在我的 int 路径参数上添加了验证,如下所示:
route1 = router.get("/start={start:int}/end={end:int}")(route1_func)
还有我的route1_func:
async def route1_func(request: Request,
start: int = Path(..., title="my start", ge=1),
end: int = Path(..., title="my end", ge=1)):
if end <= start:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)
else:
return True
这很好用......但如果可能的话,我想验证end > start 作为定义的一部分,而不是在进入route1_func 后检查它
这可能吗?
【问题讨论】:
标签: python-3.x validation server fastapi