"include super" with django templates?

33 views
Skip to first unread message

Nick Farrell

unread,
Dec 30, 2021, 5:38:25 PM12/30/21
to Django users
I would like to extend a django template which is used via the include macro. That is, I want to add additional output before or after what would otherwise be emitted.

With the normal {% block %} syntax, it's easy to use super to follow the template heirachy similar to __mro__ - but to my knowledge there isn't an equivalent for include().

For example, form.as_p() calls render() with a template (by default, django/forms/p.html). I want my application to modify this, so whenever p.html is rendered, it is wrapped by my application's supplied template. (As I want this to work for any form instance, I cannot just override the default template name)

Another example is say django/forms/templates/django/forms/widgets/number.html. It consists of a single include() statement pointint to input.html. I would like to override input.html, but in a way which eventually renders the original template, in addition to my application's template.

Any suggestions?

Thanks.

Reply all
Reply to author
Forward
0 new messages