Alex Rivera | Logout

how to run this code in django template

Asked 2011-02-16T06:53:46.717
84

this is my code :

{% for i,j in enumerate(a) %}
    {{i}} ,{{j}}
{% endfor%}

but , it show a error , i think it cant run the enumerate method ,

so how to run the enumerate in django template ,

thanks

Edit
Report

1 Answer

19

you can use {{ forloop.counter }} or {{ forloop.counter0 }} for the same effect, the latter is 0-indexed, thus more like enumerate.

answered 2011-02-16T07:02:29.343

Your Answer