首页 > 其他分享 >[FastAPI-08]Path校验

[FastAPI-08]Path校验

时间:2023-03-23 16:44:06浏览次数:42  
标签:word FastAPI 08 number num Path app

from fastapi import FastAPI,Path

app = FastAPI()

# Path校验
'''
限制接口输入的数字大小限制 100-1000
限制字符串输入的字符数量 3-8位
'''

@app.get("/number/{num}")
def number(num:int = Path(ge=100,le=1000)):
    return {"number":num}

@app.get("/word/{name}")
def word(name:str = Path(min_length=3,max_length=8)):
    return {"word":name}

标签:word,FastAPI,08,number,num,Path,app
From: https://www.cnblogs.com/leoshi/p/17248013.html

相关文章