0

I have just started working on Flask and Python. I am building an API server in which I am trying to read a csv file and display the output of csv file on /osdata at port 8080.

There might be some issue in returning the data from function. Any help would be appreciated.

from flask import Flask, request
from flask_restful import Resource, Api
import json, csv


app = Flask(__name__)
app.config["DEBUG"] = True

api = Api(app)

@app.route('/', methods=['GET'])
def home():
    return "1 2 3 Start"

@app.route('/osdata', methods=['GET'])
def osdata():
    with open("Output_data.csv", "r") as f:
        data = csv.reader(f, delimiter = "~")
        line_count = 0
        for row in data:
            print(row)
            line_count += 1
        return(row)

if __name__ == '__main__':
    app.run(port=8080) 

Geekshade
  • 29
  • 1
  • 5
  • Your `/osdata` route currently returns a *list*, which is why its not working. How do you want the CSV file to be displayed exactly? In a HTML table? – costaparas Feb 01 '21 at 05:02
  • I want to print my data on the browse in a readable format which can be stored in the database later. – Geekshade Feb 02 '21 at 06:22
  • Does this answer your question? [Converting CSV to HTML Table in Python](https://stackoverflow.com/questions/44320329/converting-csv-to-html-table-in-python) – costaparas Feb 02 '21 at 06:24

0 Answers0