{% for i in count %}
var str2 = {{leds[i]}}
var x = {{xpos[i]}}
var y = {{ypos[i]}}
var w = 30
var h = 30
var fill = {{status[i]}}
document.getElementById("FirstName").value = str2;
document.getElementById("xposition").value = x;
document.getElementById("yposition").value = y;
document.getElementById("status").value = fill;
add1(x,y,fill);
i = i+1
{% endfor %}
在这段代码中,我们希望通过for循环遍历leds,xpos,ypos列表逐个获取值。给出的错误是“无法解析余数:'[i]'来自'leds [i]'”。有什么想法吗?
答案 0 :(得分:0)
你可能想要这样的东西:
在views.py中:
stuff = zip(leds, xpos, ypos)
# and then pass this value to your template.
在你的模板中:
{% for led, x, y in stuff %}
var str2 = "{{led}}"; // notice the quotes for the JS string.
var x = {{x}};
var y = {{y}};