title: Django: Printing a queryset dynamically in the template
body: <p>How can I print the columns specified in "fields_i_want" instead of hardcoding the column names in the template code?</p>
  
  <pre><code># Let's say I have this in my view:
  foo = Foo.objects.filter(some_field='bar').select('field1', 'field2', 'field3')
  fields_i_want = ['field1', 'field2']
  
  # Then in the template I want to do something like this:
  &lt;TABLE id="some_id"&gt;    
      &lt;TBODY&gt;
          {% for row in some_var.foo %}
          &lt;tr&gt;
           {% for value in another_var.fields_i_want %}
              &lt;td&gt;{{ row[value] }}&lt;/td&gt;
           {% endfor %}
          &lt;/tr&gt;
          {% endfor %}
      &lt;/TBODY&gt;
  &lt;/TABLE&gt;
  
  # Instead of doing this:
  &lt;TABLE id="some_id"&gt;    
      &lt;TBODY&gt;
          {% for row in some_var.foo %}
          &lt;tr&gt;
              &lt;td&gt;{{ row.field1 }}&lt;/td&gt;
              &lt;td&gt;{{ row.field2 }}&lt;/td&gt;
          &lt;/tr&gt;
          {% endfor %}
      &lt;/TBODY&gt;
  &lt;/TABLE&gt;
  </code></pre>