Answer the question
In order to leave comments, you need to log in
How to get value from list by index using forloop.counter in Django template?
Greetings!
The task is as follows:
There are two lists that are passed to the template
1:
2:
It is necessary to iterate over the data list in the template and associate it with the values from the colors list, I try like this:
data = ['foo', 'bar', ...]
colors = ['#54BE50', '#76C008', ...]
{% for data_item in data %}
<mark id={{ forloop.counter }} style="background: {{ colors.forloop.counter0 }};">{{ data_item }}</mark>
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question