我用Flask做一台服务器。 我想获取包含数据的表格并将其转换为json文件。
示例
<form action="" method="POST">
<input name="your_name" value="" />
<input name="animal[1][name]" value="" />
<input name="animal[1][age]" value="" />
<input name="animal[2][name]" value="" />
<input name="animal[2][age]" value="" />
<button type="submit">test</button>
</form>
我希望这样做:
{
"your_name" : "my_name",
"animal":[
{
"name": "mono",
"age":"12"
},
{
"name": "jir",
"age":"34"
}
]
}
}
如果有人知道该怎么做,谢谢
答案 0 :(得分:0)
如何?
@app.route('/', methods=["POST"])
def process():
your_name = request.form['your_name']
(... do the same here for all your form fields ...)
your_json = {}
your_json["your_name"] = your_name
your_json["animal"] = ...