[英]sending HTML form data to python Flask
I have a form in one my html files, the code for which is: 我的html文件中有一个表单,其代码为:
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
Mechanical Turk ID: <input type="text" name="turkID">
</form>
and my python looks like : 和我的python看起来像:
@app.route("/upload", methods=['POST', 'GET'])
def upload():
img = request.files['webcam']
try:
text = request.form["turkID"]
except Exception as inst:
print type(inst) # the exception instance
print inst.args # arguments stored in .args
print inst
filename = secure_filename(img.filename)
img.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return "good"
it keeps failing the try part and the output of the exception is: 它不断使try部分失败,并且异常的输出为:
<class 'werkzeug.exceptions.BadRequestKeyError'>
('turkID',)
400: Bad Request
I've tried request.form, request.POST.get, request.POST, and cgi, but none are working. 我试过了request.form,request.POST.get,request.POST和cgi,但是没有一个工作。
Your HTML is not compatible with the Python code you have provided. 您的HTML与您提供的Python代码不兼容。 You may want to replace
demo_form.asp
in the action with /upload/
. 您可能要用
/upload/
替换demo_form.asp
中的demo_form.asp
。 You are also not sending any file to the field webcam
. 您也没有将任何文件发送到现场
webcam
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.