0

I am not able to read data from csv or json file using D3JS in my Flask application.

Here is the code of:

HTML:

    <head>
  <meta charset="UTF-8">
    <title>D3JS</title>
    <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>

<script>

    d3.csv("../data.csv", function (data) {
        console.log(data); 
    });

</script>

</body>

Flask app.py code:

from flask import Flask, render_template

app = Flask(__name__)


@app.route('/')
def hello_world():
    return render_template('historgram.html')



if __name__ == '__main__':
    app.run(debug=True)

I am receiving file not found error. Failed to load resource: the server responded with a status of 404 (NOT FOUND)

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Afiz
  • 95
  • 1
  • 6

1 Answers1

2

if data.csv is static data, you have to move the file into a directory static/ accessible from your flask server and access it via

d3.csv("/static/data.csv", function (data) {
    console.log(data); 
});
Daniel
  • 42,087
  • 4
  • 55
  • 81