Hi! Pablo Martín (goinnn[0]) and I have been working on self-referenced template recursion handling for the past few weeks. The idea is that when a template references itself when extending, recursion is avoided by skipping the current template loader (ticket #15053[1]).
This new feature would be totally backwards compatible, have no performance penalties[2] (measured with djangobench) and could, in my opinion, be one of the main features of the 1.7 release: Lot of app/CMS creators create base templates for their apps. Currently, if one of those templates needs some kind of change, the user needs to copy the template all over again, making it difficult to update their templates when they update their apps (they would need to copy the new template and then make their customizations again). Skipping the current template loader means that they would be able to create their own template (with the same path as the app template), extend it to itself and only change the blocks that need to be changed. For example: App loader: some_app/item_list.html {% block title %}Item list{% endblock title %} {% block content %} {% for item in items %} ... {% endfor %} {% endblock content %} Filesystem loader: some_app/item_list.html {% extends 'some_app/item_list.html' %} {% block title%}Custom title!{% endblock title %} This feature has also the added benefit of opening the doors to self-reference handling inside app and egg loaders. We are already giving some thought to this idea. We are aware that this is not a small change in the template engine so reviews and suggestions are highly appreciated. The pull request can be found at: https://github.com/django/django/pull/2042 Greetings, Unai Zalakain References ---------- [0] https://github.com/goinnn/ [1] https://code.djangoproject.com/ticket/15053 [2] Benchmark: Running benchmarks: template_compilation template_render template_render_simple Control: Django 1.7.dev20131205221130 (in git branch master) Experiment: Django 1.7.dev20131205224944 (in git branch ticket_15053) Running 'template_compilation' benchmark ... Min: 0.000716 -> 0.000733: 1.0240x slower Avg: 0.000981 -> 0.000996: 1.0150x slower Not significant Stddev: 0.00245 -> 0.00245: 1.0002x smaller (N = 100) Running 'template_render' benchmark ... Min: 0.014449 -> 0.014756: 1.0213x slower Avg: 0.015204 -> 0.015336: 1.0087x slower Not significant Stddev: 0.00296 -> 0.00298: 1.0053x larger (N = 100) Running 'template_render_simple' benchmark ... Min: 0.000135 -> 0.000134: 1.0071x faster Avg: 0.000385 -> 0.000385: 1.0016x faster Not significant Stddev: 0.00245 -> 0.00245: 1.0021x smaller (N = 100)
signature.asc
Description: PGP signature