我已经使用python,html和flask作为框架创建了一个网站,程序可以上传和读取1个csv文件进行处理,这就是代码 html表单(index.html) 上传过程(render_template.py) 最后一个文件是test.py,用于处理已上传的数据。
我希望程序可以以一种形式上载多个文件,可以一一处理文件,以便以后进行比较。
我已经尝试过在表单上添加<div class="d-flex justify-content-center menu_upload">
<form action = "http://localhost:5000/uploader" id="submit_form" method="POST" enctype="multipart/form-data">
<div class="form-group" id="input-holder">
<input type="file" name="file" id="submitted_file" style="border:1px solid red";/>
</div>
<div class="text-center">
<input type="submit" id="submit_button" class="btn btn-primary btn-sx mt-2" value="submit"/>
</div>
</form></div>
import os
from flask import flask, render_template, request, url_for, redirect, flash
from werkzeug.utils import secure_filename
import test
UPLOAD_FOLDER = 'static/upload_file'
ALLOWED_EXTENSIONS = set(['csv'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
def index():
return render_template('index.html')
@app.route("/uploader", method=['GET','POST','OPTIONS'])
def uploader():
file = request.files['file']
allowed1 = allowed_file(file.filename)
if (
file and allowed1
):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config(['UPLOAD_FOLDER'], filename))
flash('successful upload')
first_data = []
sec_data = []
....
first_data, sec_data .... = test.data_set(filename)
show = 1
return render_template('index.html', filename=filename,
first_data=first_data,
sec_data=sec_data,
...........
show = show)
multiple
并在render_template.py上添加更多file
和filename
之类的file2
和filename2
的方法,但是没有按照我想要的方式工作。我该如何处理?用户可以根据需要在最少3个文件和最多8个文件之间上传数据。0 个答案:
没有答案