Tom's corner of the internet

Profiling Django templates with Django-Debug-Toolbar

April 18, 2013 - Under:

My last post about the speed of Django’s templating language caused a bit of a stir and it was clear that people didn’t really have a clue how long the templates were taking to render in their applications.

Enter Template-timings

Template-timings is a panel for Django-debug-toolbar (which everyone should be using, right?) that lets you see a breakdown of the rendering process. It currently gives you timing information on each block and template rendered in a convenient panel. It works on {%raw%}{% blocks %}, {% extends %} and {% include %}‘ed{%endraw%} templates.

django debug toolbar KPL2PKO7


Check out the GitHub Repo for installation instructions

How does this work?

Its quite simple. This function replaces Template.render and BlockNode.render. It simply records how long the real render function takes.

Django’s template rendering code is somewhat complex, and this is the best solution I could find. Its not perfect - there doesn’t seem to be a way to tell what block belongs to what template for example, but it works.

Gravatar for

Written by Tom Forbes who lives and works in London building useful things with Python and Django. I usually blog about security, my projects and random experiments