上一页 1 2 3 4 5 6 ··· 12 下一页
摘要: from fastapi import APIRouter, Depends from typing import Optional, List from pydantic import Field, BaseModel app05 = APIRouter() class UserInfo(Base 阅读全文
posted @ 2021-05-29 15:07 苦行僧冬*婷 阅读(214) 评论(0) 推荐(0)
摘要: FastAPI 依赖注入系统 依赖注入是指: 在编程中,为了使代码运行成功,先导入或声明其所需要的依赖,如子函数,数据库等(类似django中的类视图,有封装,继承,多态三大特性) 提高代码的复用率 共享数据库连接 增强安全,认证,角色管理权限 FastAPI的兼容性 支持所有的sql(关系型数据库 阅读全文
posted @ 2021-05-29 14:01 苦行僧冬*婷 阅读(283) 评论(0) 推荐(0)
摘要: 默认HttpExceptionError # 默认HttpException 错误异常 @app04.get('/http_exception') async def http_exception(city: str): if city != 'BeiJing': raise HTTPExcepti 阅读全文
posted @ 2021-05-29 13:47 苦行僧冬*婷 阅读(897) 评论(2) 推荐(0)
摘要: @app04.post( '/path_opration_configuration', #url路径,每个路径代表一种资源 tags=['path_opration_configuration'], #路径名称 response_model=UserOut, response_descriptio 阅读全文
posted @ 2021-05-28 23:18 苦行僧冬*婷 阅读(250) 评论(0) 推荐(0)
摘要: from fastapi.staticfiles import StaticFiles app.mount(path='/coronavirus/',app=StaticFiles(directory=' ./coronavirus/static', name='static')) 阅读全文
posted @ 2021-05-28 21:57 苦行僧冬*婷 阅读(866) 评论(0) 推荐(0)
摘要: File类 上传单个文件 from fastapi import File from typing import List @app04.post('single_file') async def single_file(file: bytes = File(...)) return {'files 阅读全文
posted @ 2021-05-28 18:00 苦行僧冬*婷 阅读(1665) 评论(0) 推荐(0)
摘要: @app04.post('/status_code',status_code = 200) def status_code(): return {'status_code':200} from fastapi import status @app04.post('/status_code/attri 阅读全文
posted @ 2021-05-28 15:23 苦行僧冬*婷 阅读(92) 评论(0) 推荐(0)
摘要: 1.定义一个响应体数据格式 from pydantic import BaseModel, EmailStr, Field class UserOut(BaseModel): username: str phone: str = '10086' email: EmailStr full_name: 阅读全文
posted @ 2021-05-28 14:49 苦行僧冬*婷 阅读(168) 评论(0) 推荐(0)
摘要: from fastapi import Cookie,Header 1.设置Cookie参数,设置Header参数 # cookie 和 header @app03.get('/cookie') # cookie必须是键值对,使用Cookie类产生cookie键值对 def cookie(cooki 阅读全文
posted @ 2021-05-28 11:01 苦行僧冬*婷 阅读(215) 评论(0) 推荐(0)
摘要: FastAPI之路径参数以及验证 from fastapi import APIRouter,Path app03 = APIRouter() @app03.get('/path/{num}') async def path_parameter_validation( num: int = Path 阅读全文
posted @ 2021-05-27 14:24 苦行僧冬*婷 阅读(489) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 ··· 12 下一页