Opened 8 years ago

Closed 5 years ago

#6691 closed New feature (fixed)

Make it possible for template loaders to optionally return compiled Template object

Reported by: redvasily Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords:
Cc: redvasily@…, jefferya@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by ramiro)

Django now uses two stage template loading process:

This patch follows our (very) small discussion on mailing list:

  1. First find_template_source() which uses settings.TEMPLATE_LOADERS to actually load template
  2. get_template_from_string() which is essentially a factory function for Template objects

I modified django.template.loader.find_template_source() function and renamed it to find_template() to check if return value of template loader is a tuple - if it's a tuple than standard it proceeds with standard template loading process:

origin = make_origin(display_name, loader, name, dirs)
template = Template(template, origin, name)

But if it fails to unpack return value of template loader it assumes that template loader returned compiled template object and returns it.

This change is backwards compatible and opens a lot of new possibilities for template system.

Attachments (1)

templateloader.diff (2.8 KB) - added by redvasily 8 years ago.
Diff implementing this ticket

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by redvasily

Diff implementing this ticket

comment:1 Changed 8 years ago by programmerq

  • Cc jefferya@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by ramiro

  • Description modified (diff)

comment:3 Changed 8 years ago by programmerq

  • Needs documentation set
  • Triage Stage changed from Unreviewed to Design decision needed

comment:4 Changed 5 years ago by julien

  • Type set to New feature

comment:5 Changed 5 years ago by julien

  • Severity set to Normal

comment:6 Changed 5 years ago by Alex

  • Easy pickings unset
  • Resolution set to fixed
  • Status changed from new to closed
  • UI/UX unset

This was fixed my Mike Malone's cache template loader patch that went in a while ago.

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