FastAPI查询Query单个或多个值列表,python
Posted zhangphil
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FastAPI查询Query单个或多个值列表,python相关的知识,希望对你有一定的参考价值。
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赋多个值时候:
以上是关于FastAPI查询Query单个或多个值列表,python的主要内容,如果未能解决你的问题,请参考以下文章
FastAPI学习-3.get 请求 query params 查询参数
数据库DQL(Data Query Language)语言学习之三:排序查询
何时/何地在 FastAPI 中使用正文/路径/查询/字段?