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.
For example:
{% for user in users %}
{% include “userDetail.html” %}
{% endfor %}
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.
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.
Does anybody know a solution to this problem? Or does anybody have any other ideas why render_to_response would be taking so long?
[edit] I should mention that I enabled Django’s caching template loader, and it only saved about 1 second. Flattening the template was significantly quicker.
Try out Jinja2, it’s ~10x faster than Django’s templating library, from what I’ve read.