Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango templates: insert values for javascript variables
    text
    copied!<p>I am trying to assign some javascript variables in a Django template.</p> <p>I am having a problem where the values I am assigning are being written to the page properly (I can see them in the page source), but still come up as <code>null</code>.</p> <p>I am doing this:</p> <pre><code>&lt;script type="text/javascript"&gt; var coords = []; {% for i in item_list %} coords.push([ {{i.x}}, {{i.y}} ]); {% endfor %} &lt;/script&gt; </code></pre> <p>This is the page source that is produced:</p> <pre><code>coords.push([ -320.435118373, -149.333637576 ]); coords.push([ -120.41321373 , -329.312376 ]); ... </code></pre> <p>It seems to be perfectly valid javascript, however, using Firebug to view the value of <code>coords</code>, this is what is produced:</p> <pre><code>[[null, null], [null, null], [null, null]...[null, null]] </code></pre> <p>So it's apparent that each of the <code>push()</code> calls is going off correctly and a new array of size 2 is being added each time. However, for some reason, the numeric literals all evaluate to <code>null</code>.</p> <p>Does anyone know how I can get these values to be used properly?</p> <p><strong>UPDATE:</strong> It appears that the values in the array are fine until I pass them into the jQuery flot plugin:</p> <pre><code>$.plot($('#mapWrapper'), coords, options); </code></pre> <p>So I guess this doesn't have anything to do with the way I am using the Django templates after all. Still, I am curious as to what the problem is with <code>$.plot</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload