2

I am having a list in the name 'bestforproglist'. Also I had a for loop like this

{% for act in activities %} <div style="float:left;">{{ act.spotcategoryactivity }}</div> <div class="progit"> <div class="prog_c" > <div id="prog_p" style="width:20%;"></div> </div> <span id="p_caps">{{ ____________ }}%</span><br/> </div> {% endfor %} 

in the above code, in the space of underline, how should i have have first item in the list when the loop is in first iteration, the second item in the list when the loop is in second iteration and so on...

I tried

<span id="p_caps">{{ mylist[ {{forloop.counter}} ] }}</span><br/> 

But it's not working.

1
  • you cant use list['key'] in templates, it can be accessed as list.key instead Commented Nov 25, 2010 at 7:17

3 Answers 3

5

What is mylist? If you want to iterate over multiple lists, perhaps you should zip them and pass them into the template? Then you can use something like

 {% for x,y in zipped_list %} 

and use both the items rather than the indexing thing you're trying.

Sign up to request clarification or add additional context in comments.

Comments

1

If it's important to have activities and bestforproglist synchronized like this then it's best to zip() them in the view and then iterate over both of them together.

{% for act, prog in zippedlist %} 

Comments

0

In template , code like this """ mylist[ {{forloop.counter}} ] """ won`t work.

use "." instead.

http://docs.djangoproject.com/en/dev/topics/templates/#variables

this will make you clear about how to output things in template

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.