Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
How do I link a csv file to flask?

I have a CSV file of readings from a sensor that I would like to graph with chart.js on a flask server, however I am getting 404 errors when trying to access the CSV file, since I am getting 404 errors I am assuming that I need to actually path the CSV file in flask, but I cant figure out how to do this, I'm coming across a lot of irrelevant information about using flask to make and fill a database but I need to pass the database to an html page to parse for graphing.

Could someone please help me learn how to do this?

Code that I'm testing and playing around with for reading CSV files in JavaScript. Has the route specified in flask code below!

<script>
    //path is from html file location to db location is this right?
    d3.csv("../db/test.csv", function(data) {
        for (var i = 0; i < data.length; i++) {
            console.log(data[i].Test1);
            console.log(data[i].Test2);
            console.log(data[i].Test3);
        }
    });
</script>

Test CSV file.

Test1, Test2, Test3
1, 2, 3

404 Error Details

Any help to better understand how to do this is much appreciated!

forgot my flask code!

@app.route('/test')
def test():
    #every thing that links the csv to flask would go here? Or would I need a more specific function for the csv file?
    return render_template('test.html'), 201
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I FOUND IT!!! Here is the article I used in case anyone ever has a similar issue!

https://medium.com/@rovai/from-data-to-graph-a-web-jorney-with-flask-and-sqlite-6c2ec9c0ad0

flask code

#Retrieve data from db (logs/log_db/sht.#.db ; # = run_id = SHT30_#.log, #)
def getData():
    conn = sqlite3.connect('logs/log_db/sht.%s.db' %run_id)
    cur = conn.cursor()
    for row in cur.execute('''SELECT Itn, Temp, Humi FROM READING'''):
        Itn = str(row[0])
        Temp = str(row[1])
        Humi = str(row[2])
    conn.close()
    return Itn, Temp, Humi
    
#main route
@app.route("/")
def index():
    Itn, Temp, Humi = getData()
    templateData = {
        'Itn': Itn,
        'Temp': Temp,
        'Humi': Humi
    }
    return(render_template('index.html', **templateData))

In my index.html i used {{ variables }} to display the data on the page.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!