title: For Loop from database using Jinja2 Template
body: <p><strong>Goal:</strong> <code>{% for loop %}</code> over a list (using <code>Jinja2</code>) and then print out results <code>{{print}}</code> in a <code>HTML</code> table using Bootstrap. <br>
  <strong>Problem:</strong> List is not printing in the template.<br></p>
  
  <p>In the <code>view_config</code>, I used <code>query</code> <code>.all()</code> to return a list of all the <code>assessment_results</code> objects. They are returning... I confirmed this via terminal/print debugging. However, the <code>for loop</code> is not returning the values needed to populate a table; as <a href="http://jinja.pocoo.org/docs/dev/templates/#loop-filtering" rel="nofollow noreferrer">read in Jinja2 tutorial</a>. I don't think I need to use a <code>for loop</code> in the <code>view_config</code> as I have seen others do (<a href="https://stackoverflow.com/questions/13350091/looping-over-a-list-in-a-jinja2-template">see here</a>), but I am new to this and am trying to figure out how these two programs (<code>SQLALCHEMY</code> and <code>Jinja2</code>) interact. </p>
  
  <p>An example from the printout after using <code>.all()</code> mentioned above: </p>
  
  <pre><code>[&lt;Assessment_Result(owner='&lt;User(username ='baseball', firstname ='Jen', lastname ='See', email='girl@aol.com')&gt;', assessment='&lt;Assessment(name='Becoming a Leader', text='better decisions')&gt;')&gt;]
  </code></pre>
  
  <p>view_config code:<br>
  <strong><code>views.py</code></strong></p>
  
  <pre><code>@view_config(route_name='assessment_results', request_method='GET', renderer='templates/assessment_results.jinja2')
  def all_assessment_results(request):
      with transaction.manager: # &lt; --- THIS WAS THE ISSUE ! 
          assessment_results = api.retrieve_assessment_results()
          if not assessment_results:
              raise HTTPNotFound()
          return {'assessment_results': assessment_results}
  </code></pre>
  
  <p>Corresponding Jinja2 template using Bootstrap:<br>
  <strong><code>assessment_results.jinja2</code></strong></p>
  
  <pre><code>&lt;div class="container"&gt;
      &lt;table class="table table-hover"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;td&gt; Assessment ID &lt;/td&gt;
                  &lt;td&gt; Assessment &lt;/td&gt;
                  &lt;td&gt; Owner &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  {% for x in assessment_results %}
                  &lt;td&gt;{{ x.assessments|e }}&lt;/td&gt;
                  &lt;td&gt;{{ x.owners|e}}&lt;/td&gt;
                  {% else %}
                  &lt;td&gt;&lt;em&gt;no users found&lt;/em&gt;&lt;/td&gt;
                  {% endfor %}
              &lt;/tr&gt;
          &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  </code></pre>