TomNash
TomNash

Reputation: 3288

How do you iterate over an integer variable in Jinja?

I have a variable questionCount which is passed to the HTML page and used to create row column entries in a table. This number can vary and needs to be used in a for loop.

I need to do something like the following:

{% for num in 1..questionCount %}
    <td>Question {{num}}</td>
{% endfor %}

But this does not work. What is the appropriate way to do this?

Upvotes: 2

Views: 3017

Answers (1)

hlt
hlt

Reputation: 6317

1..questionCount is not valid Python (but Ruby).

Try range(1, questionCount + 1) instead to generate values from 1 to questionCount. See also the docs about range.

Upvotes: 3

Related Questions