随笔分类 - FastAPI框架学习记录
这一部分记录FastAPI学习过程中的点点滴滴
摘要:# 如何通过路径参数配置依赖,如何在路径中使用依赖, 路径操作装饰器中的多依赖 >类似继承 # 写没有返回值的子依赖 async def verify_token(x_token: str = Header(..., convert_underscores=True)): """ 验证x_token
阅读全文
摘要:from fastapi import Depends def query(q:Optional[str] = None): return q def sub_query(q: str = Depends(query), last_query: Optionnal[str] = None): if
阅读全文
摘要:from fastapi import APIRouter, Depends from typing import Optional, List from pydantic import Field, BaseModel app05 = APIRouter() class UserInfo(Base
阅读全文
摘要:FastAPI 依赖注入系统 依赖注入是指: 在编程中,为了使代码运行成功,先导入或声明其所需要的依赖,如子函数,数据库等(类似django中的类视图,有封装,继承,多态三大特性) 提高代码的复用率 共享数据库连接 增强安全,认证,角色管理权限 FastAPI的兼容性 支持所有的sql(关系型数据库
阅读全文
摘要:默认HttpExceptionError # 默认HttpException 错误异常 @app04.get('/http_exception') async def http_exception(city: str): if city != 'BeiJing': raise HTTPExcepti
阅读全文
摘要:@app04.post( '/path_opration_configuration', #url路径,每个路径代表一种资源 tags=['path_opration_configuration'], #路径名称 response_model=UserOut, response_descriptio
阅读全文
摘要:from fastapi.staticfiles import StaticFiles app.mount(path='/coronavirus/',app=StaticFiles(directory=' ./coronavirus/static', name='static'))
阅读全文
摘要:File类 上传单个文件 from fastapi import File from typing import List @app04.post('single_file') async def single_file(file: bytes = File(...)) return {'files
阅读全文
摘要:@app04.post('/status_code',status_code = 200) def status_code(): return {'status_code':200} from fastapi import status @app04.post('/status_code/attri
阅读全文
摘要:1.定义一个响应体数据格式 from pydantic import BaseModel, EmailStr, Field class UserOut(BaseModel): username: str phone: str = '10086' email: EmailStr full_name:
阅读全文
摘要:from fastapi import Cookie,Header 1.设置Cookie参数,设置Header参数 # cookie 和 header @app03.get('/cookie') # cookie必须是键值对,使用Cookie类产生cookie键值对 def cookie(cooki
阅读全文
摘要:FastAPI之路径参数以及验证 from fastapi import APIRouter,Path app03 = APIRouter() @app03.get('/path/{num}') async def path_parameter_validation( num: int = Path
阅读全文
摘要:项目目录: tutorial包下的init文件 .表示当前目录 from .chapter03 import app03 from .chapter04 import app04 from .chapter05 import app05 chapter03下创建新的app from fastapi
阅读全文
摘要:""" 测试 FastApi的post请求中的数据验证, 使用的是Body 类似于Path,Query ,embed=True 请求体中使用 json key-value """ from fastapi import FastAPI, Body, Request from fastapi.resp
阅读全文
摘要:引用博文: https://blog.csdn.net/wgPython/article/details/107525950 FastAPI之get请求 """ 本模块用来测试 FastApi 中 get和post请求参数: path: 路径参数 ?: 查询参数 以及 数据的校验,和异常处理 """
阅读全文
摘要:1.pydantic库介绍 pydantic 是一个基于python类型提示来定义数据验证,序列化,文档的库 使用python的类型注解 来进行数据校验和settings管理 pydantic可以在代码运行时提供类型提示, 数据校验失败时提供友好的错误提示 定义数据应该如何在纯规范的python中保
阅读全文
摘要:Fastapi Swagger乱码 /docs乱码 样式错误 参考博客: https://blog.csdn.net/qq_29622543/article/details/117085056
阅读全文

浙公网安备 33010602011771号