Flask单Form表单多按钮提交
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--分界线-->
<hr/>
<p>上传模型</p>
<form action="/uploadForm" enctype="multipart/form-data" method="post">
<table>
<tbody>
<tr>
<td>算法类型:</td>
<td><input type="text" name="algoCategory"></td>
</tr>
<tr>
<td>任务类型:</td>
<td><input type="text" name="task"></td>
</tr>
<tr>
<td>模型文件:</td>
<td><input type="file" name="model"></td>
</tr>
<tr>
<td>提交:</td>
<td><input type="submit" name="提交"></td>
</tr>
</tbody>
</table>
</form>
<!--分界线-->
<hr/>
<p>已注册模型列表</p>
<table>
<tbody>
<tr>
<td>唯一ID</td>
<td>任务类型</td>
<td>算法类型</td>
<td>模型文件</td>
</tr>
{% for item in content %}
<tr>
<form action="/deleteModel" method="post">
<td><input type="text" name="uuid" value={{item}}></td>
<td><input type="text" name="algoCategory" value={{content[item]["algoCategory"]}}></td>
<td><input type="text" name="task" value={{content[item]["task"]}}></td>
<td><input type="text" name="ModelName" value={{content[item]["ModelName"]}}></td>
<td><input type="submit" name="delete" value="删除" onclick="return confirm('确认删除吗?')"></td>
<td><input type="submit" name="init" value="初始化模型"></td>
<td><input type="submit" name="test" value="测试"></td>
</form>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
@app.route("/deleteModel",methods=['GET','POST'])
def deleteModel():
if request.method =="POST":
if request.values.get("delete"):
uuid = request.form.get("uuid")
jsonres = jsonHelper.delete(uuid,r"./modelData.json")
return render_template('index.html',content=jsonres)
elif request.values.get("init"):
return "初始化成功"
elif request.values.get("test"):
return "测试成功"