title: Jinja2 template evaluate variable as attribute
body: <p>I have a Jinja2 Template I'm working on for a database editing app, and I'm trying to make it 'extendible' - rather than hard-coding the editing page, I'm passing a list of attributes that I want in the table, and using a for loop to iterate over them.  It works aside from one thing - in the hardcoded version, I use an attribute of an object that's being passed to see if that value has been set (they are all boolean), but I can't see how to get jinja2 to take the 'capability' and use that as an attribute of the 'pupil' object; i would have used 'eval' in Python, but can't see how to get this to work.  Here's an idea of the code:</p>
  
  <pre><code>{%  for capability in capability_list %}
      &lt;tr&gt;
          &lt;td&gt;{{ capability }}&lt;/td&gt;
          &lt;td&gt;
              {% if pupil.capability %}
                  &lt;img src="{{request.static_url('gdpr_permissions:static/tick.png')}}" width="25"&gt;
              {% else %}
                  &lt;img src="{{request.static_url('gdpr_permissions:static/cross.png')}}" width="25"&gt;
              {% endif %}
          &lt;/td&gt;
          &lt;td&gt;
              &lt;div class="onoffswitch"&gt;
                  &lt;input type="checkbox" name="{{ capability }}" class="onoffswitch-checkbox" value ='No' id="{{ capability }}" checked&gt;
                      &lt;label class="onoffswitch-label" for="{{ capability }}"&gt;
                      &lt;span class="onoffswitch-inner"&gt;&lt;/span&gt;
                      &lt;span class="onoffswitch-switch"&gt;&lt;/span&gt;
                      &lt;/label&gt;
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      {% endfor %}
  </code></pre>
  
  <p>It's the <code>{% if pupil.capability %}</code> part that doesn't work - I want this to become (say) <code>pupil.web_access</code> and <code>pupil.database_access</code> etc., following the capability list which is being iterated over.</p>
  
  <p>Any ideas on how to get this working with jinja2, or how else it can be approached?  The other idea I had was to iterate over the current settings in the python backend and then pass a list of booleans separately, but this seems to be adding an extra level of complexity.</p>