4Manuals

  • PDF Cloud HOME

以一种形式包含多个上传的CSV文件 Download

    如何将文本边界框与pyplot.Rectangle对齐? 导入类问题 具有Iframe表单的HTML文件,使用框架外的按钮通过JQuery提交表单按钮 在Python数据框中选择列时出错 CSS在像素中设置多个颜色渐变? 创建一个没有固定布局的HTML表,设置最大宽度,并且行不换行但溢出:隐藏 使用Rabbit的pika确认消息 如何在按住键的同时暂停VideoStream? Python OpenCV TypeError:无法处理此数据类型 使用buildozer不会下载sdl2_image

我已经使用python,html和flask作为框架创建了一个网站,程序可以上传和读取1个csv文件进行处理,这就是代码

html表单(index.html)

<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>

上传过程(render_template.py)

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)

最后一个文件是test.py,用于处理已上传的数据。 我希望程序可以以一种形式上载多个文件,可以一一处理文件,以便以后进行比较。 我已经尝试过在表单上添加multiple并在render_template.py上添加更多file和filename之类的file2和filename2的方法,但是没有按照我想要的方式工作。我该如何处理?用户可以根据需要在最少3个文件和最多8个文件之间上传数据。

0 个答案:

没有答案



Similar searches
    局部变量是否在不同的numa节点上分配? 您可以在JSX中创建来自组件的传递组件的react组件吗? 在Laravel中使用多种条件编写QUERY 在异步循环中设置useState挂钩 解释器中的手动vs GC内存管理以及使用malloc / free