【发布时间】:2022-06-17 16:56:28
【问题描述】:
我有一个GET 方法,路径中有请求参数:
@router.get('/users/{user_id}')
async def get_user_from_string(user_id: str):
return User(user_id)
是否可以从请求中获取基本 url 原始路径('/users/{user_id}')?
我尝试过使用以下方式:
path = [route for route in request.scope['router'].routes if
route.endpoint == request.scope['endpoint']][0].path
但它不起作用,我得到:
AttributeError: 'Mount' 对象没有属性 'endpoint'
【问题讨论】:
标签: python url-routing fastapi