I am passing a list uans as a context for my template. I want to iterate over uans to display values within it. My code is as follows:
{% for q in qlist %}
<span>You answered: {{ uans.{{forloop.counter0}} }}</span>
{% endfor %}
But I'm getting this error:
Could not parse the remainder: '{{forloop.counter0' from 'uans.{{forloop.counter0'
It works fine if I write uans.0 ,, uans.1 and so on.
I want to use the forloop counter as an index.
I want to iterate over uansonly using the counter.
Please suggest a solution. Thanks :)
qlisthas the questions anduanshas the option which the user answered.qlistis a QuerySet.uansjust has the options as strings inside itquestions_and_answers = zip(qlist, uans)in the view, then{% for q, a in questions_and_answers %}in your template.zip()and i'm getting the expected results. Thanks :)