title: Speed comparison: server-generated HTML vs templates?
body: <p>I'm using Google App Engine's version of Django templates in Python.</p>
  
  <p>Is there a major performance difference between putting loops in the template vs putting it in the python page handlers?</p>
  
  <p>For example, I'm comparing something like this:</p>
  
  <pre><code>{% for i in items %}
     &lt;div id="item_{{i.key}}"&gt;    
         {{i.text}}
     &lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>Vs something like this inside my python code:</p>
  
  <pre><code>def returnHtml(items):
    item_array = []
    for i in items:
       item_array.append("&lt;div id='item_%s'&gt;%s&lt;/div&gt;" % (i.id, i.text)
    return "".join(item_array)
  </code></pre>
  
  <p>... which then gets directly inserted into a django template in a tag like:</p>
  
  <pre><code>{{ item_html }}
  </code></pre>
  
  <p>This is a trivial example, realistically, I've got more complex loops inside of loops, etc.  I like putting the logic inside of the python code because it's much easier to maintain.  But I'm worried about the impact on performance.</p>
  
  <p>Any thoughts?  Thanks.</p>