1

I have table data in PostGreSQL which is easily accessed in my Django View. Now I want to pass this data to a javascript .js file whose purpose is to use this data and visualize using d3.js

This is what I have tried as an example, but no luck

views.py

def view_function(request):
  data = 'test_data'
  return render(request, 'test.html', context = {'data':data})

test.html

<head>
</head>
<body>
  <script src="{% static 'test.js' %}">myFunction({{data}})</script>
</body>

test.js

function myFunction(view_data) {
 console.log(view_data);
}
Surya Tej
  • 1,342
  • 2
  • 15
  • 25
  • Hope this helps https://stackoverflow.com/questions/38654599/django-best-way-to-pass-data-to-javascript and https://www.geeksforgeeks.org/how-to-pass-data-to-javascript-in-django-framework/ – Not A Bot Nov 11 '20 at 12:51
  • @NotABot No the links do not help, I want to pass data to seperate Js file and not use the data in the html file inside – Surya Tej Nov 11 '20 at 14:34

0 Answers0