Flask Showing Shape of Uploaded CSV File


I have app.py file:

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

app = Flask(__name__)

@app.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        df = pd.read_csv(request.files.get('file'))
        return render_template('upload.html', shape=df.shape)
    return render_template('upload.html')

if __name__ == '__main__':

and upload.html file:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
<form method=post enctype=multipart/form-data>
    <input type=file name=file>
    <input type=submit value=Upload>
Shape is: {{ shape }}

and dummy.csv file:


I would like to show shape of the data when I upload the csv file. I cannot get the shape of the data with my implementation. I appreciate any hints/ helps.


Here is the solution:

Create a templates folder and put your upload.html file inside the templates folder. Since, you do not have it inside the templates folder, flask is returning you jinga2 template not found error.

Just like all the images need to be inside static folder, all the html templates need to be inside the templates folder inorder for your application to work.

Hope this helps!

Answered By – BishwashK

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published