title: How can I evaluate a View context variable as a Template variable in Django?
body: <p>I'd like to pass a context variable from a view into my template to direct what the template should display.</p>
  
  <p>I have a context list variable <code>column_headers</code> that dictates the number of columns in a list page table, along with the header text that should be used.</p>
  
  <pre><code>context['column_list'] = [
      _('Animal'),
      _('Owner'),
      _('Reason'),
      _('Time'),
      _('Vet'),
      _('Status')
  ]
  </code></pre>
  
  <p>I'd like to include a related list variable that tells the template which variable to include for each cell in the corresponding column, for example:</p>
  
  <pre><code>context['cell_vars'] = [
      'patient',
      'client',
      'reason',
      'start_time',
      'attending_staff',
      'status'
  ]
  </code></pre>
  
  <p>such that the variable <code>FOO.client</code> would appear in the <code>'Owner'</code> column, and <code>FOO.attending_staff</code> would appear in the <code>'Vet'</code> column, etc.</p>
  
  <p>Doing this allows me have a single list.html page to handle all of my lists.</p>
  
  <p>So, my question is whether this is a good idea, and if so, how would I go about evaluating a 'string' presented as a context variable i.e.</p>
  
  <pre><code>{% for row in rows %} #loop over list data
      {{ row.attending_staff }} #work fine, but...
      {{ row.SOME_VARIABLE_THAT_HAS_VALUE_OF_'attending_staff' }} #doesn't
  {% endfor %}
  </code></pre>
  
  <p>So, if <code>x='attending_staff'</code> I need to be able to evaluate the variable <code>row.x</code> such that it actually evaluates <code>row.attending_staff</code> </p>
  
  <p>The use case for this is very defined and involves display logic only (not data retrieval since the data is already in the loop variable <code>row</code>) so IMO could be a good fit for a template. </p>
  
  <p>It would allow me to have a single 'list.hml' template to handle pretty much all of my lists, rather than what I have currently which is 10 x foo_list.html pages, all being very similar to each other (table structure, looping logic, icons, links, css class names etc).</p>