[英]Starlette/FastApi route path components with forward slash
I have defined a route in Starlette/FastApi -我在 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"
I have some forward slash in the path components, and I want to make the following request to access post_method
我在路径组件中有一些正斜杠,我想发出以下请求以访问
post_method
curl -X POST "http://127.0.0.1:5000/api/path%2Fpath" -H "accept: application/json" -d ""
results in the 404 error in the Starlette/Fastapi logs.导致 Starlette/Fastapi 日志中出现 404 错误。
INFO: 127.0.0.1:50233 - "POST /api/path/path HTTP/1.1" 404
How to get the correct path components?如何获得正确的路径组件?
You can use Starlette built-in path convertor您可以使用 Starlette 内置路径转换器
@app.route("/path/{param:path}", name="path-convertor")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.