title: sending json data from django to d3.js
body: <p>i am trying to pass a queryset in django's views.py to d3.js.</p>
  
  <p>views.py :</p>
  
  <p>def index(request):
      qs = DCPOWERSTATS.objects.all().values('TS','PuE').order_by('TS') 
      return render(request, 'dashboard/dash.html', context=qs})</p>
  
  <p>dash.html :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;style&gt;
  
  .chart div {
  font: 10px sans-serif;
  background-color: steelblue;
  text-align: right;
  padding: 3px;
  margin: 1px;
  color: white;
               }
  
  &lt;/style&gt;
  &lt;div class="chart"&gt;&lt;/div&gt;
  &lt;script src="//d3js.org/d3.v3.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  
  var data = {{ data_json }};
  
  var x = d3.scale.linear()
            .domain([0, d3.max(data)])
            .range([0, 420]);
  
  d3.select(".chart")
    .selectAll("div")
    .data(data)
    .enter().append("div")
    .style("width", function(d) { return x(d) + "px"; })
    .text(function(d) { return d; });
  
   &lt;/script&gt;
  </code></pre>
  
  <p>I need to make changes in views.py and dash.html to create something like :
  <a href="https://bl.ocks.org/mbostock/3885304" rel="nofollow noreferrer">https://bl.ocks.org/mbostock/3885304</a></p>
  
  <p>All previous answers are confusing.I need a solution for views.py as well as dash.html. I also need to know the perfect way of sending queryset results to javascript.</p>
  
  <p>Thanks!</p>