我在尝试将值从 HTML 表单<input>
元素传递到表单的action
属性并将其发送到 FastAPI 服务器时遇到以下问题。
这是 Jinja2 (HTML) 模板的加载方式:
# Test TEMPLATES
@app.get("/test",response_class=HTMLResponse)
async def read_item(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
Run Code Online (Sandbox Code Playgroud)
我的 HTML 表单:
<form action="/disableSubCategory/{{subCatName}}">
<label for="subCatName">SubCategory:</label><br>
<input type="text" id="subCatName" name="subCatName" value=""><br>
<input type="submit" value="Disable">
</form>
Run Code Online (Sandbox Code Playgroud)
我的 FastAPI 端点将在表单操作中调用:
<form action="/disableSubCategory/{{subCatName}}">
<label for="subCatName">SubCategory:</label><br>
<input type="text" id="subCatName" name="subCatName" value=""><br>
<input type="submit" value="Disable">
</form>
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
"GET /disableSubCategory/?subCatName=Barber HTTP/1.1" 404 Not Found
Run Code Online (Sandbox Code Playgroud)
我想要实现的是以下 FastAPI 调用:
/disableSubCategory/{subCatName} ==> "/disableSubCategory/Barber"
Run Code Online (Sandbox Code Playgroud)
谁能帮助我理解我做错了什么?
谢谢。狮子座