我已经在Starlette / FastApi中定义了一条路线-
@router.post("/{part}")
def post_method(part):
return "ok"
@router.post("/{part}/{another_part}")
def another_post_method(part, another_part):
return "ok"
我在路径组件中有一个正斜杠,我想发出以下请求以访问post_method
curl -X POST "http://127.0.0.1:5000/api/path%2Fpath" -H "accept: application/json" -d ""
导致Starlette / Fastapi日志中出现404错误。
INFO: 127.0.0.1:50233 - "POST /api/path/path HTTP/1.1" 404
如何获取正确的路径组件?
答案 0 :(得分:1)
您可以使用Starlette内置路径转换器
@app.route("/path/{param:path}", name="path-convertor")
答案 1 :(得分:0)
在fastapi gitter中来自Marcelo Trylesinski(Kludex)的响应: