FastAPI查询Query单个或多个值列表,python
from typing import List
import uvicorn
from fastapi import FastAPI, Query
app = FastAPI()
@app.get("/item")
async def get_item(q: List[str] = Query(["a", "b"], max_length=5, min_length=1)): # a,b为默认值。
return {"q": q, "size": len(q)}
if __name__ == '__main__':
uvicorn.run(app=app, host="0.0.0.0", debug=True)
q不传入任何值,返回默认值a,b:
当给查询值q赋多个值时候: