Opened 16 years ago

Closed 14 years ago

#7815 closed (wontfix)

Let Context handle include, extends and inclusion_tag template loading

Reported by: Johannes Dollinger Owned by: nobody
Component: Template system Version: dev
Severity: Keywords: feature
Cc: goliath.mailinglist@…, research@… Triage Stage: Design decision needed
Has patch: no Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

  • Add a loader kwarg to Context which should be something with a get_template(name) function. Default would be django.template.loader.
  • Provide get_template() and select_template() methods on Context, use these in include, extends and inclusion_tag.
  • Cache templates in Context, optionally: provide a way to populate this cache.
  • Remove ConstantIncludeNode since caching would provide the same benefits and it causes problems with recursive includes.

This would fix

  • #2949 - templating engine too tightly tied to TEMPLATE_DIRS in the settings
  • #3544 - recursive includes
  • #4278 - get_template should accept a dirs argument
  • #6834 - support for templates to be loaded from dynamically-selected directories

Example:

class PrefixLoader:
    def __init__(self, prefix_list):
        self.prefix_list = prefix_list
    def get_template(name):
        from django.template.loader import select_template
        return select_template(['%s/%s' % (prefix, name) for prefix in self.prefix_list])

tpl.render(Context({}, loader=PrefixLoader(['a', 'b', 'c'])))

Attachments (1)

7815.tplrf.diff (7.0 KB ) - added by Johannes Dollinger 16 years ago.
depends on tplrf.2.diff and tplrf-tests.diff from #7806

Download all attachments as: .zip

Change History (9)

by Johannes Dollinger, 16 years ago

Attachment: 7815.tplrf.diff added

depends on tplrf.2.diff and tplrf-tests.diff from #7806

comment:1 by Johannes Dollinger, 16 years ago

Needs documentation: set
Needs tests: set
patch -p0 tplrf.2.diff
patch -p0 tplrf-tests.diff
patch -p1 7815.tplrf.diff

mostly done. contains a test for recursive includes, but no tests for the loader feature yet.

comment:2 by David Danier <goliath.mailinglist@…>, 16 years ago

Cc: goliath.mailinglist@… added

comment:3 by Johannes Dollinger, 16 years ago

This would also fix #7931.

Forgot to mention in the ticket description: this is a backwards incompatible change. If you rely on compile time side effects (e.g. {% load %}) in included templates, that will break.

comment:4 by Eric Holscher, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedDesign decision needed

comment:5 by Jacob, 16 years ago

milestone: 1.0post-1.0

comment:6 by anonymous, 16 years ago

Cc: research@… added

comment:7 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:8 by Russell Keith-Magee, 14 years ago

Resolution: wontfix
Status: newclosed

The three (remaining) individual tickets (#3544, #4278, #6834) are all good ideas, but an omnibus patch makes it really hard to evaluate which bits are fixing what. It's also an area that needs a lot of cleanup following the 1.2 template loader changes.

Closing wontfix, mostly as a procedural thing; we'd prefer to see single patches for single issues, or a merging of issues into a single ticket (resulting in the previous tickets getting closed).

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