Django templates - nesting includes in loops

I have a template that includes many nested loops. We have different parts of the pages, divided into separate template files, because we reuse them by combining them in different ways for different views.

For example: {% for user in% users} {% include "userDetail.html"%} {% endfor%}

Our database contains about 40 thousand records. I have identified a problem for the template system. render_to_response takes about 11 seconds. I thought Django was not caching templates, so maybe this is an I / O issue.

I aligned one of our templates so that it doesn’t exist at all, and shaved off for about 5 seconds. But this is not very useful in our situation when we reuse a lot of template code.

Does anyone know a solution to this problem? Or does anyone have other ideas why render_to_response will last so long?

[edit] It should be noted that I turned on the Django caching template loader, and it only lasted about 1 second. Pattern smoothing was significantly faster.

+5
source share
2 answers

Try Jinja2 , it is ~ 10 times faster than the Django template library from what I read.

0
source

U can use Java Script for client-side loops instead of letting django do this.

http://blog.iiilx.com/programming/benchmarking-my-app-out-of-curiosity/

-3
source

All Articles