How to extend Django template objects?

1 view
Skip to first unread message

Bryan Chow

unread,
Apr 14, 2006, 7:27:23 PM4/14/06
to Django users
Is there a "correct" way to extend a Django template that doesn't exist
on the filesystem? I couldn't find any mention of this in the
documentation.

I'm creating template objects programmatically, and I want one of these
objects to extend another, just as a template on the filesystem can {%
extends %}
another file.

I'm using magic-removal from svn. Any help would be appreciated.

Bryan

Adrian Holovaty

unread,
Apr 20, 2006, 6:24:47 PM4/20/06
to django...@googlegroups.com
On 4/14/06, Bryan Chow <fullf...@gmail.com> wrote:
> Is there a "correct" way to extend a Django template that doesn't exist
> on the filesystem? I couldn't find any mention of this in the
> documentation.
>
> I'm creating template objects programmatically, and I want one of these
> objects to extend another, just as a template on the filesystem can {%
> extends %}
> another file.

Hi Bryan,

The current best way to do that would be to change
django.template.loader.template_source_loaders to be a custom loader
(see the "Templates for Python programmers" docs). An example of this
is in run_tests() method in tests/othertests/templates.py. It's
hackish, but it works. If there's interest, we can expose things so
that you pass in the loader list as an optional argument to
get_template().

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

Bryan Chow

unread,
Apr 21, 2006, 12:36:18 AM4/21/06
to Django users
Hi Adrian,

Thanks for the reply, and for the suggestion. I've been working with
Ian Clelland, who submitted this patch a few days ago to address the
issue:

http://code.djangoproject.com/ticket/1650

There is definitely lots of interest over here for this functionality
to become part of Django, as it seems natural for {% extends %} to be
possible for non-filesystem templates.

Best Regards,
Bryan

Reply all
Reply to author
Forward
0 new messages