Flask接受表单数据
“enctype”指定了表单数据的编码类型,“multipart/form-data”被用于指定表单数据为文件。
“action”属性指定表单的处理程序
当<input>
“type”: "submit"时,此时意味着这个按钮是可以触发表单提交行为;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<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>
</body>
</html>
@app.route("/uploadForm",methods=['GET','POST'])
def uploadForm():
algoCategory = request.form.get("algoCategory")
task = request.form.get("task")
model = request.files.get("model")
model.save(os.path.join("AI_Model_Zoo",model.filename))
print("algoCategory",algoCategory,"task",task)
return "ok"