I have an 'int Array' e.g. format [0,3,5,4,6], I have passed this through context. Now in my HTML page I have my JavaScript/JQuery... I thought it'd be as simple doing {% for i in array %} i {% endfor %} but this doesn't seem to be working for me to access the values from a loop. Can you pass a context to JavaScript from Django? how can I get around this problem?
edit the passing shouldn't be a problem if I access an index of the array by creating a variable in my view and passing that -> this will output fine in the script by simply doing {{contextgivenname}}
edit2: if i do {{arrayname}} it will return the first value. But only the first value. So the only way to return all is to loop through it; which isn't working.
anArray2 = [int(i['age']) for i in anArray]
{
'anArray2':anArray2
}
In JavaScript/Jquery when I'm trying to grab the data and use it {{anArray2}} = first value in it.. but if I loop via as mentioned above then nothing.
{{ array_var_context|safe }}{% for i in anArray2 %}i{% endfor%}should work, although won't be proper javascript array. better to use json.dumps in your view context.