Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda