# 如何通过路径参数配置依赖,如何在路径中使用依赖, --- 路径操作装饰器中的多依赖 --->类似继承 # 写没有返回值的子依赖 async def verify_token(x_token: str = Header(..., convert_underscores=True)): """ 验证x_token值 是否存在 :param x_token: header里设置键值对 :return: x_token if x_token else raise exception """ if x_token != ‘fake‘: return x_token raise HTTPException(status_code=400, detail=‘x_token is valid‘, headers={‘x_token‘: None}) def verify_key(x_key: str = Header(..., convert_underscores=True)): if x_key != ‘fake_key‘: return x_key raise HTTPException(status_code=400, detail=‘x_key is valid‘, headers={‘x_token‘: None}) @app05.get(‘/path_opration_verify‘, dependencies=[Depends(verify_token), Depends(verify_key)]) async def path_opration_verify(): return {‘user‘: ‘user01‘}, {‘user‘: ‘user02‘}
原文:https://www.cnblogs.com/learn-record/p/14825633.html