上一页 1 2 3 4 5 6 7 ··· 51 下一页
摘要: 设置默认值 @app.get("/items/") async def read_items(q: Union[str, None] = Query(default=None, max_length=50)): # Query适用于查询参数中,设置默认值为None,并且规定最大长度为50 resul 阅读全文
posted @ 2024-02-28 17:17 我在路上回头看 阅读(35) 评论(0) 推荐(0) 编辑
摘要: 单个查询字符串 @app.get('/index/{username}') def index(username: str, id: int): # id为查询字符串 ?id=5 return {"message": "success", "username": username, "id": id 阅读全文
posted @ 2024-02-28 17:15 我在路上回头看 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 路径参数额外校验Path from fastapi import Path app = FastAPI() @app.get('/items/{item_id}') async def read_items(item_id: str = Path(default=None, max_length=3 阅读全文
posted @ 2024-02-28 17:12 我在路上回头看 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 路径参数 # 单一参数 @app.get('/index/{id}') def index(id: int): return {"message": "success", "data": id} # 多参数 @app.get('/index/{username}/{id}') def index(u 阅读全文
posted @ 2024-02-28 16:55 我在路上回头看 阅读(8) 评论(0) 推荐(0) 编辑
摘要: mount应用挂载 1.创建主app应用对象实例,注册所属的路由信息 from fastapi import FastAPI from fastapi.response import JSONResponse app = FastAPI(title='主应用', description='主应用描述 阅读全文
posted @ 2024-02-28 16:54 我在路上回头看 阅读(214) 评论(0) 推荐(0) 编辑
摘要: APIRouter实例的路由注册 API端点路由注册大致分为3种: 1.基于app实例对象提供的装饰器或函数进行注册 2.基于FastAPI提供的APIRouter类的实例对象提供的装饰器或函数进行注册 3.通过直接实例化APIRoute对象且添加的方式进行注册 路由注册方式 基于APIRouter 阅读全文
posted @ 2024-02-28 16:52 我在路上回头看 阅读(116) 评论(0) 推荐(0) 编辑
摘要: APIRouter和 APIRoute的区别 # APIRouter 主要是定义路由组,可以理解为一个路由组的根路由,类似于flask的蓝图 # APIRoute 表示具体路由节点对象 阅读全文
posted @ 2024-02-28 16:51 我在路上回头看 阅读(67) 评论(0) 推荐(0) 编辑
摘要: APIRouter参数介绍 class APIRouter(routing.Router): def __init__( self, *, prefix: str = "", # 表示当前路由分组的url前缀 tags: Optional[List[Union[str, Enum]]] = None 阅读全文
posted @ 2024-02-28 16:49 我在路上回头看 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 一个路由配置多个http请求方法 app = FastAPI(routes=None) # 方式一:app.api_route() @app.api_route(path='/index', methods=['GET','POST']) async def index(): return {'ms 阅读全文
posted @ 2024-02-28 16:48 我在路上回头看 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 节点元数据参数说明 # 拿app.get()方法的参数来说明,其他的差不多类似 def get( self, path: str, *, response_model: Optional[Type[Any]] = None, status_code: Optional[int] = None, ta 阅读全文
posted @ 2024-02-28 16:46 我在路上回头看 阅读(28) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 51 下一页