score:1

Accepted answer

You could try like this

Define data variable in django template filea and can be accessed in js file

Here the data variable in index.html is accessible in Javascript file

index.html

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<h1>hello d3</h1>
<div>
</div>
<script>
    var data = '{% static "data.csv" %}'
</script>
<script type="text/javascript" src="{% static 'js/d3.js' %}">
</script>
</body>
</html>

/static/js/d3.js

data varibale is passed from index.html

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

Related Query