title: How to access list using variable indexes in Django templates?
body: <p>Say, I have two lists of objects, <code>foo</code> and <code>bar</code>. In a Django template, while looping through <code>foo</code>, there's a counter that keeps track of the current index/iteration and the counter is used to access <code>bar</code>. The problem here is I don't think Django template system supports accessing list using variable indexes. Is that true? If so, is there any workaround for the problem (other than repeating the same piece of html/template code with hard-coded indexes)? </p>
  
  <p>Code demonstration:</p>
  
  <pre><code>{% for x in foo %}
    &lt;span&gt;{{ x.name }} vs. {{ bar.{{ forloop.counter0 }}.name }}&lt;/span&gt;
  {% endfor %}
  </code></pre>
  
  <p>Django template doesn't like <code>{{ bar.{{ forloop.counter0 }}.name }}</code></p>
  
  <p>Note: I am using Django 1.4</p>