title: Django Templates -- nesting includes in loops
body: <p>I've got a template that has a lot of includes nested in for loops.  We've got different parts of pages broken out into separate template files because we reuse them by piecing them together in different ways for different views.</p>
  
  <p>For example:
      {% for user in users %}
          {% include "userDetail.html" %}
      {% endfor %}</p>
  
  <p>We have some 40k records in our database.  I've pinpointed the issue to the templating system.  render_to_response takes about 11 seconds to run.  I figured maybe Django wasn't caching the templates, so maybe it was an I/O issue.</p>
  
  <p>I flatted one of our templates so there's no includes at all, and shaved off about 5 seconds.  But this isn't very helpful in our situation where we reuse a lot of the template code.</p>
  
  <p>Does anybody know a solution to this problem?  Or does anybody have any other ideas why render_to_response would be taking so long?</p>
  
  <p><strong>[edit]</strong> I should mention that I enabled Django's caching template loader, and it only saved about 1 second.  Flattening the template was significantly quicker.</p>