Flask Programming

Hands On No. 7 : Working With CSV Files

Resources

Source Code of hello.py
from flask import Flask
from flask import render_template

app = Flask(__name__, template_folder='templates')
    
@app.route('/')
def listfiles():
    with open('mentor-data.csv', 'r') as file:
        csv_reader = csv.reader(file)
        studentdata = []
        for row in csv_reader:
            studentdata.append(row)
    n = len(studentdata) -1
    return render_template('View-Data.html', studentdata=studentdata,n=n)
    

Source Code of View-Data.html

<!DOCTYPE html>
<html>
<head>
<title>Test App</title>
</head>
<body>
<table width="800px" align="center">
<tr>
<td align="center">{{ n }} records found </td>
</tr>
</table>
<table width="800px" align="center">

{% for temp in studentdata %}
<tr>
{% for t in temp %}
<td>{{ t }} </td>
{% endfor %}
</tr>
{% endfor %}
</table>
</body>
</html>