Python 输入[type=file]返回空值
我有一个脚本,可以根据webpy cookbook创建一个带有表单的弹出窗口:Python 输入[type=file]返回空值,python,upload,web.py,Python,Upload,Web.py,我有一个脚本,可以根据webpy cookbook创建一个带有表单的弹出窗口: jQuery('#logo').click(function(){ var content = ('<h1>Upload logo</h1>' + '<form method="POST" enctype="multipart/form-data" action="/upload">' + '<input type="file" id=
jQuery('#logo').click(function(){
var content = ('<h1>Upload logo</h1>' +
'<form method="POST" enctype="multipart/form-data" action="/upload">' +
'<input type="file" id="myfile" accept="image/jpeg,image/png,image/gif" />' +
'<button id="upload" type="submit">Загрузить</button></form>'
);
popup(content);
});
但是当我试图上传文件时,我总是得到空的存储对象。元素没有name属性,该属性将指示表单提交中的文件名。名称是必需的,因为您可以在一个表单中有多个输入字段,包括file
字段。添加name=
可以解决您的问题:
'<input type="file" name="myfile" id="myfile" accept="image/jpeg,image/png,image/gif" />'
// ^^^^^^^^^^^^^
“”
// ^^^^^^^^^^^^^
元素没有name属性,该属性将指示表单提交中的文件名。名称是必需的,因为您可以在一个表单中有多个输入字段,包括file
字段。添加name=
可以解决您的问题:
'<input type="file" name="myfile" id="myfile" accept="image/jpeg,image/png,image/gif" />'
// ^^^^^^^^^^^^^
“”
// ^^^^^^^^^^^^^