With Flask how to show my data from my CSV file (JSON) on a webpage?
You should be using tablib for that:
# -*- coding: utf-8 -*-from flask import Flaskimport tablibimport osapp = Flask (__name__)#fun vardataset = tablib.Dataset()with open(os.path.join(os.path.dirname(__file__),'out.csv'))) as f: dataset.csv = f.read()@app.route("/")def index(): return dataset.htmlif __name__ == "__main__": app.run()
Much cleaner and simpler.
OP's solution (edited out from the question):
Nevermind I found the solution myself :
# -*- coding: utf-8 -*-from flask import Flaskimport osapp = Flask (__name__)#fun varfilepath = os.path.join(os.path.dirname(__file__),'out.csv')open_read = open(filepath,'r')page =''while True: read_data = open_read.readline() page += '<p>%s</p>' % read_data if open_read.readline() == '': break@app.route("/")def index(): return pageif __name__ == "__main__": app.run()