Hello,given this approach, what if the third party app wants to self-extend a django admin template for example?
The application should provide a separate template directory and force users load it in their TEMPLATE_DIRS. Then what happens if the developer wants to self-extend that third party app's template? He can't use the filesystem loader because it will be ignored, but using the app loader wouldn't result in an infinite loop? (the last template is found by the app_loader -given the installed_apps order is correct-, then the third-party app's template is found which in turn leads back to the app loader and tries to override template for which we started).
What I'm trying to say is that maybe this approach means you're stuck with one self-extension per app-loader. Sorry if this thought is wrong, it's just my initial reaction.
Pantelis On 12/06/2013 04:36 PM, unai wrote:
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)
-- Pantelis Petridis Software Architect / Engineer e-mail: [email protected] url: Yawd web applications <http://www.yawd.eu> -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/52A47E7F.7020101%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
<<attachment: ppetridis.vcf>>
