title: Passing a django dictionary ( or json file) to javascript function
body: <p>I know there are a few ways to access django variables in javascript .However I am not able to send a django dictionary or json object to javascript .
  My code :
  view.py</p>
  <pre><code>items_raw = Items.objects.all() 
  items = list(items_raw.values())
  return render(request,'admin_dashboard/products.html',{'items':json.dump(items)})
  </code></pre>
  <p>Template :</p>
  <pre><code>{% for item in items %}
        &lt;tr&gt;
           &lt;td&gt;&lt;a onclick=edit_product(&quot;{{item|safe}}&quot;)&gt;{{ item.product_name }}&lt;/a&gt;&lt;/td&gt; 
    {%endfor%}
  &lt;!--- JAVASCRIPT HERE ---!&gt;
  &lt;script&gt;
  function edit_product(item){
  console.log(item.id) }
  &lt;/script&gt;
  </code></pre>
  <p>Here &quot;items&quot; is a json object which is a list of dictionaries (the dict has more than 20 keys and values ) there are thousands of item in list . I only want to pass the particular item user selected to js function . Is there any simple way to do it ?</p>
  <ol>
  <li>I don't want to include serializers or rest-framework .</li>
  <li>I don't care for security ,I will be the only one using this .</li>
  <li>I don't want to put all 20 pairs of the dictionary in html like:</li>
  </ol>
  <pre><code>&lt;input type=&quot;hidden&quot; id=&quot;myVar&quot; name=&quot;variable&quot; data-prod=&quot;{{ item.product_name }}&quot; data-id=&quot;{{ item.id }}&quot;&gt;
  </code></pre>