我有一个程序,我在其中读取CSV文件并验证多个CSV文件标题列,其中列标题计数应相同,而列标题名称应相同(如果不匹配,则显示一些错误消息)< / p>
我已经在python中完成了验证,但是我不知道如何在javascript / jquery中进行验证。我想从HTML文件
进行操作用于验证的Python程序:
from flask import Flask, render_template
import os
import csv
import pandas as pd
import numpy as np
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@app.route("/")
def index():
print("Loading the root file")
return render_template("upload.html")
@app.route("/upload", methods=['POST'])
def upload():
target = os.path.join(APP_ROOT, 'input/')
print("target-",target)
if not os.path.isdir(target):
os.mkdir(target)
abs_path_files=[]
for file in request.files.getlist("source_fileName"):
print("file-",file)
filename = file.filename
print("filename-",filename)
destination = "/".join([target, filename])
print("destination-",destination)
file.save(destination)
print("file>",file)
tempFile = os.path.abspath(destination)
abs_path_files.append(tempFile)
print("abs_path_files - " ,abs_path_files)
global files_list
files_list=abs_path_files
print("files_list-",files_list)
return redirect('/compute',)
@app.route("/compute")# Here we are performing the Header columns Validation
def compute():
dataFrames=[]
for f in files_list:
dataFrame=pd.read_csv(f)
dataFrames.append(dataFrame)
col_in_files = set([",".join(list(f.column.values)) for f in dataFrames])
if len(col_in_files)==1:
# After validation it will go for the other computations
.......................................................
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> upload </title>
</head>
<body>
<div class="container">
<h1>Large Data Generation</h1>
<form id = "upload-form" action="{{ url_for('upload') }}" method="POST" enctype="multipart/form-data">
<div id="file-selector">
<p>
<strong>Source File: </strong>
<input id="source_fileName" type="file" name="source_fileName" accept="csv/*" multiple />
</p>
</div>
<input type="submit" value="Generate Data" id="upload-button" >
</form>
</div>
</body>