Opened 9 years ago

Closed 9 years ago

#11175 closed (wontfix)

Automatic template inheritance

Reported by: Denis Martinez <deuns.martinez@…> Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Sometimes I have templates in my framework that I would like to override (Satchmo for example).

So I copy the .html in my template directory.
The drawback is that I can't create a template.html in my project and extend with {% extends "template.html" %}, because that would mean recursive includes.

Copying is bad for maintainability and it duplicates template code. So I suggest a templatetag {% autoextends %} that would search the next template directories for a template to extend, with the same filename. Like so:


{% block test %}Test{% endblock %}


{% autoextends %}
{% block test %}{{block.super}}. It works!{% endblock %}

Change History (3)

comment:1 Changed 9 years ago by dc

I think that implicity will lead to many strange errors.

Better add parent dir to the TEMPLATE_DIRS and use

{% extends "base_template/index.html" %}
{% block test %}{{block.super}}. It works!{% endblock %}

in derived_template/index.html

comment:2 Changed 9 years ago by Denis

This tag should exist at least for convenience; if you don't like it, you don't have to use it.

If the functionality is correctly implemented, I don't know what kind of errors you're thinking about.
The django code can (should) make sure that recursion problems will never happen.

Your solution seems hackish to me, possibly more error-prone. In this case you are imposing a restriction on the parent directory's name, that we have to take in consideration when deploying on multiple servers.

comment:3 Changed 9 years ago by Alex Gaynor

Resolution: wontfix
Status: newclosed

This templatetag is impossible, neither the context nor the tag knows the name of the template being rendered.

Note: See TracTickets for help on using tickets.
Back to Top