0

I want user to upload CSV file and the app should show the shape to the user. I am receiving the error '400 Bad Request: The browser (or proxy) sent a request that this server could not understand.'

from flask import Flask, request, render_template
import pandas as pd
import csv

app = Flask(__name__)

@app.route('/')
def my_form():
    return render_template('form_ex.html')

@app.route('/home')
@app.route('/', methods = ['POST'])
def my_form_post():
    if request.method == 'POST':
        file = request.files['csv_data']
        data = pd.read_csv(file)
        print(data) 
        asa = str(data.shape)
        return render_template('form_ex.html', shape=df.shape)
<!DOCTYPE HTML>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <form method="post">
        <p>Enter JDE file </p><br />
        <input type="file" name="csv_data"  id="userId" />
        <input type="submit" value="Submit" />
    </form>
Shape is: {{ shape }}
</body>
</html>
davidism
  • 121,510
  • 29
  • 395
  • 339

0 Answers0