Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda