Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#1650 closed enhancement (fixed)

[patch] Allow templates to extend from parents in local context

Reported by: clelland@… Owned by: Adrian Holovaty
Component: Template system Version: magic-removal
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


It can be useful for templates to extend a base template which does not necessarily exist on the filesystem -- for example, the base template may be stored in the database, or it may be generated at runtime.

This patch allows a template object in the curent context to be used as a base template for inheritance.


>>> from django.template import Context, Template, loader
>>> child = Template("{% extends parent %}{% block one %}Hello, {{ name }}{% endblock %}")
>>> parent = Template("<h1>{% block one %}Name{% endblock %}</h1>")
>>> child.render(Context({'name': 'World', 'parent': parent}))

returns "<h1>Hello, World</h1>"

Attachments (1)

template-loader.diff (3.1 KB) - added by clelland@… 12 years ago.

Download all attachments as: .zip

Change History (2)

Changed 12 years ago by clelland@…

Attachment: template-loader.diff added

comment:1 Changed 12 years ago by Jacob

Resolution: fixed
Status: newclosed

Fixed in [3465].

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