python flask中怎样获取form的id或name属性。注意是form的属性不是用户的输入值

比如html中:
<form method="post" enctype=multipart/form-data id="0" >
<input type=file name=file >
<input type=submit value=上传>
</form>

在后端的python中怎么能获取到这个form的id?
想判断
if request.method == 'POST' 且 form的id=0时
再进行下一步。

月关宝盒
浏览 532回答 2
2回答

小怪兽爱吃肉

123456<form&nbsp;action="upload"&nbsp;method="post"&nbsp;enctype="multipart/form-data">&nbsp;&nbsp;&nbsp;&nbsp;<input&nbsp;type="hidden"&nbsp;style="visibility:&nbsp;hidden;"&nbsp;name="formname"&nbsp;value="name0"&nbsp;/>&nbsp;&nbsp;&nbsp;&nbsp;<input&nbsp;type="hidden"&nbsp;style="visibility:&nbsp;hidden;"&nbsp;name="formid"&nbsp;value="0"&nbsp;/>&nbsp;&nbsp;&nbsp;&nbsp;<input&nbsp;type="file"&nbsp;name="file"&nbsp;/><br&nbsp;/>&nbsp;&nbsp;&nbsp;&nbsp;<input&nbsp;type="submit"&nbsp;value="Upload"&nbsp;/></form>&nbsp;12345678910@app.route('/upload',&nbsp;methods=['GET',&nbsp;'POST'])def&nbsp;upload():&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;request.method&nbsp;==&nbsp;'GET':&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;render_template('upload.html')&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;request.method&nbsp;==&nbsp;'POST':&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f&nbsp;=&nbsp;request.files['file']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;request.form['formname'],request.form['formid']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fname&nbsp;=&nbsp;secure_filename(f.filename)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.save(os.path.join(UPLOAD_FOLDER,&nbsp;fname))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;'上传成功'&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python