Flask 不列出多个文件的输出
Flask does not list outputs of multiple files
我正在使用 Flask 渲染一些基于使用 Flask 重新上传和 werkzeug 将图像作为输入的分析。虽然输入接受多张图片,但输出只渲染一张图片,而不是上传的所有图片。
我没有收到任何错误消息。
HTML代码:
<form method="POST" action="" enctype="multipart/form-data"><p>
<input type="file" name="file" multiple
accept="image/x-png,image/gif,image/jpeg">
<input type="submit" value="Upload">
Post请求
@app.route('/', methods=['POST'])
def upload_image():
if request.method == 'POST':
# checks whether or not the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No file selected for uploading')
return redirect(request.url)
files = request.files.getlist('files[]')
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(os.getcwd() +
UPLOAD_INPUT_IMAGES_FOLDER, file.filename))
flash('File successfully uploaded')
# calls the ocr_processing function to perform text extraction
extracted_text = ocr_processing(file)
print(extracted_text)
match = extracted_text.lower()
df = pd.read_csv("/Users/ri/Desktop/DPL/DPL.csv")
for row in df.Pattern_String:
result = ratio(row, match)
print(result)
if result >= 10:
else:
return render_template('uploads/results.html',
msg='Processed successfully!',
match=match,
img_src=UPLOAD_INPUT_IMAGES_FOLDER + file.filename)
else:
flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
return redirect(request.url)
你定义了files = request.files.getlist('files[]')
,但是你没有使用它。
您需要遍历所有上传的文件,即您需要例如一个 for 循环。
我会开始将误导性输入名称 file
重命名为 files
,然后重新开始。
我正在使用 Flask 渲染一些基于使用 Flask 重新上传和 werkzeug 将图像作为输入的分析。虽然输入接受多张图片,但输出只渲染一张图片,而不是上传的所有图片。 我没有收到任何错误消息。
HTML代码:
<form method="POST" action="" enctype="multipart/form-data"><p>
<input type="file" name="file" multiple
accept="image/x-png,image/gif,image/jpeg">
<input type="submit" value="Upload">
Post请求
@app.route('/', methods=['POST'])
def upload_image():
if request.method == 'POST':
# checks whether or not the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No file selected for uploading')
return redirect(request.url)
files = request.files.getlist('files[]')
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(os.getcwd() +
UPLOAD_INPUT_IMAGES_FOLDER, file.filename))
flash('File successfully uploaded')
# calls the ocr_processing function to perform text extraction
extracted_text = ocr_processing(file)
print(extracted_text)
match = extracted_text.lower()
df = pd.read_csv("/Users/ri/Desktop/DPL/DPL.csv")
for row in df.Pattern_String:
result = ratio(row, match)
print(result)
if result >= 10:
else:
return render_template('uploads/results.html',
msg='Processed successfully!',
match=match,
img_src=UPLOAD_INPUT_IMAGES_FOLDER + file.filename)
else:
flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
return redirect(request.url)
你定义了files = request.files.getlist('files[]')
,但是你没有使用它。
您需要遍历所有上传的文件,即您需要例如一个 for 循环。
我会开始将误导性输入名称 file
重命名为 files
,然后重新开始。