Accepted answer

First You would need to look how Django server works and to serve static file in Django link.

You can not just load static file as d3.csv("data.csv")

Then Follow these steps

1. Add Following in

STATIC_URL = '/static/'
    os.path.join(BASE_DIR, 'static'),

2. Create static folder inside root project folder and add csv file inside static folder

3. The you need to serve static file and load

  • {% load static %} at top
  • {% static "data.csv" %}

{% load static %}
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <script src=""></script>
<h1>hello d3</h1>
    d3.csv('{%  static 'data.csv' %}', function (err, csv) {

If your file is not static and user uploaded media file just replace d3.csv code as below. And before this you need add MEDIA_URL and MEDIA_ROOT in settings as below

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

  • visualisation.html
d3.csv('{{ object.file.url}}', function (err, csv) {

Related Query