上一页 1 2 3 4 5 6 ··· 51 下一页
摘要: 上传文件 # file仅适用于小文件 @app.post("/files/") async def create_file(file: bytes | None = File(default=None)): if not file: return {"message": "No file sent" 阅读全文
posted @ 2024-02-28 17:43 我在路上回头看 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 模型基本用法 from pydantic import BaseModel class Item(BaseModel): # 通过继承BaseModel name: str price: float is_offer: Union[bool, None] = None 常用的模型属性和方法 dict 阅读全文
posted @ 2024-02-28 17:42 我在路上回头看 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 将对象转为json兼容类型 from fastapi.encoders import jsonable_encoder # jsonable_encoder编码器 class User(BaseModel): uname: str date_signed: Optional[datetime] = 阅读全文
posted @ 2024-02-28 17:36 我在路上回头看 阅读(62) 评论(0) 推荐(0) 编辑
摘要: 设置响应状态码 from fastapi import status from fastapi.responses import JSONResponse # 方式一 @router.get("/user", status_code=status.HTTP_202_ACCEPTED) def use 阅读全文
posted @ 2024-02-28 17:35 我在路上回头看 阅读(29) 评论(0) 推荐(0) 编辑
摘要: 管理Cookie # 设置 @app.post("/create/") def create_cookie(response: Response): # 设置cookie对应的key-value值 response.set_cookie(key="name", value="jack") respo 阅读全文
posted @ 2024-02-28 17:35 我在路上回头看 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 表单数据Form class User(BaseModel): uname: str password: str @app.post("/form", response_model=User) def post_form(uname: str = Form(default=None), passwo 阅读全文
posted @ 2024-02-28 17:30 我在路上回头看 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 请求对象Request相关属性和函数 # request属性和函数 app 表示当前请求所属的上下文应用对象 url 表示当前请求完整的url对象 base_url 表示请求的服务url地址 method 表示此次请求使用的http方式 client 包含当前请求来源的客户端信息 Cookies 表 阅读全文
posted @ 2024-02-28 17:26 我在路上回头看 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 请求头Header @app.get("/header") async def read_items(x_token: Optional[str] = Header(None, convert_underscores=True), host: Optional[str] = Header(None) 阅读全文
posted @ 2024-02-28 17:25 我在路上回头看 阅读(59) 评论(0) 推荐(0) 编辑
摘要: 请求体中的单一值Body from typing import Annotated from fastapi import Body,FastAPI # Body()表示嵌入请求体中的单一值 from pydantic import BaseModel app = FastAPI() class I 阅读全文
posted @ 2024-02-28 17:24 我在路上回头看 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 请求体映射 from typing import Union from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class Item(BaseModel): name: str price: floa 阅读全文
posted @ 2024-02-28 17:22 我在路上回头看 阅读(18) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 51 下一页