烧瓶:上传多个文件时,列表为空

时间:2019-09-25 16:45:27

标签: python html flask

我正在尝试上传多个文件,并将它们保存在指定的文件夹中,以供以后使用。当我在输入中使用getlist时,列表显示为空。

我尝试过

<input type="file" name="rename" multiple/> 
<input type="file" name="rename" webkitdirectory mozdirectory/>
<input type="file" name="rename" webkitdirectory multiple/> 


files = request.files.getlist("rename")
files = request.files.getlist("rename[]")

HTML:

<form action="" method ="POST"> 

    <form action = "" method = "post" enctype="multipart/form-data">  
        <p>Upload files to be renamed.</p>
        <input type="file" name="rename" multiple/>  
        <input type = "submit" value="Upload">  <br><br>
    </form> 

</form>

Flask应用程序:

# route for renaming a directory/group of files
@app.route('/renamesubmit', methods=['GET', 'POST'])
def rename2():
    path = './HARCresults/'
    renamepath = path + 'rename/'
    csvname = session.get('csv', "None")
    csv = path + csvname
    if not os.path.exists(renamepath):
        os.mkdir(renamepath)
    if request.method == 'POST':  
        files = request.files.getlist("rename")
        for f in files:
            f.save(os.path.join(renamepath, f.filename))
        #rename(renamepath, csv)
        return redirect('/results')
    else:
        return render_template('renamesubmit.html')

0 个答案:

没有答案