我有以下内容
<form action="classify_upload" method="post" id="upload-form">
<input type="file" name="imagefile" id="imagefile"/>
<input type="submit" />
</form>
在我的 Flask Web 应用程序中,我有以下规则:
@webapp.route('/upload', methods=['POST'])
def upload():
try:
imagefile = flask.request.files['imagefile']
...
except Exception as err:
...
但我得到了error 400: bad request
,我的谷歌搜索告诉我 Flask 找不到该密钥下的文件'imagefile'
这是 html 中输入的名称。有什么想法为什么找不到它吗?
原来我需要包括enctype
在表单中,所以 html 应该是
<form action="classify_upload" method="post" id="upload-form" enctype="multipart/form-data">
<input type="file" name="imagefile" id="imagefile"/>
<input type="submit" />
</form>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)