python - With Flask how to show my data from my CSV file (JSON) on a webpage? -


i show content of csv file on simple webpage :

do know flask have >

i quite new on flask,i read tutorial basic flask don't totally it.

enter image description here

nevermind found solution myself :

# -*- coding: utf-8 -*- flask import flask import os  app = flask (__name__)  #fun var  filepath = 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 page   if __name__ == "__main__":     app.run() 

you should using tablib that:

# -*- coding: utf-8 -*- flask import flask import tablib import os  app = flask (__name__)  #fun var  dataset = tablib.dataset() open(os.path.join(os.path.dirname(__file__),'out.csv'))) f:     dataset.csv = f.read()   @app.route("/") def index():     return dataset.html   if __name__ == "__main__":     app.run() 

much cleaner , simpler.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -