I have a CSV file called random.csv which I want to render on a html page if the user is logged in. I've tried using tablib for this.
__init__.py
from flask import Flask
import tablib
app = Flask(__name__)
dataset = tablib.Dataset()
with open(os.path.join(os.path.dirname(__file__), 'random.csv')) as f:
dataset.csv = f.read()
routes.py
@app.route('/dataset', methods=['GET', 'POST'])
@login_required
def dataset():
return dataset.html
This is the index.html file from where I want to link to the html page for the csv file.
{% extends "base.html" %}
{% block content %}
<p><a href="{{ url_for('dataset') }}">Click to see CSV</a> </p>
{% endblock %}
And this is the dataset.html file where I want to see the CSV data.
{% extends "base.html" %}
{% block content %}
{% endblock %}
I'm getting this error:
AttributeError: 'function' object has no attribute 'html'
The error is on the line in routes.py file where I return the dataset.html file.
question from:
https://stackoverflow.com/questions/65936700/displaying-csv-file-as-html-page-using-flask 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…