In a Django template the following syntax works just fine:

{% for test in testing.1 %}

but when replacing the fixed 1 with a dynamic variable from an outer for loop it doesn't work at all:

{% for i in range %}
    {% for test in testing.i %}

When printing {{ i }} it shows 1, 2 and 3 like it should. Do I have to convert the i-variable somehow? Or can't I use the iterator variable there?

1 Answers

0
creyD On Best Solutions

As @svrw commented: a dictionary lookup can't use a variable as key. I had to prepare the data so that I could use

{% for element in range %}
    {% for test in element %}

and get the correct output. My data in the views.py I changed from this:

range = {
    1: data1,
    2: data2,
    3: data3
}

to:

data1 = [element1, element2, element3 ...]
...
range = [data1, data2, data3]