Opened 9 years ago

Closed 9 years ago

#24783 closed New feature (fixed)

Template libraries and built-ins should be registered through the engine

Reported by: Preston Timmons Owned by: Preston Timmons <prestontimmons@…>
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: andrei.avk@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django template libraries and builtins depend on global variables in django.template.base. This is messy, but also restrictive. The only way to specify template tag modules is by adding a package in INSTALLED_APPS that has a templatetags directory. Modifying builtins is a hack. And the LoadNode has a hard dependency on django.apps. Preferably, libraries and builtins should be specified and live on the Engine instance instead.

I think this can be cleaned up by having libraries and builtins configured via the DjangoTemplates backend. This would build on Mark Tamlyn's idea in #12772:

TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'libraries': {
                'admin.urls': 'django.contrib.admin.templatetags.admin_urls',                  
                'my_tags': 'path.to.some.module',
            },
            'builtins': {
                'path.to.builtins_module',
            }
        },
    },
]

Change History (11)

comment:1 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

comment:2 by andrei kulakov, 9 years ago

Owner: changed from nobody to andrei kulakov
Status: newassigned

comment:3 by Preston Timmons, 9 years ago

Hi akulokov,

I have a PR close to ready on this ticket. Just wanted to let you know since you assigned yourself, and I forgot to assign myself earlier.

comment:4 by andrei kulakov, 9 years ago

@preston, no problem, unassigning myself..

comment:5 by andrei kulakov, 9 years ago

Owner: andrei kulakov removed
Status: assignednew

comment:6 by andrei kulakov, 9 years ago

Cc: andrei.avk@… added

comment:7 by Preston Timmons, 9 years ago

Has patch: set

comment:8 by Tim Graham, 9 years ago

Patch needs improvement: set

comment:9 by Tim Graham, 9 years ago

Should we close #17085 "Deprecate "add_to_builtins" and turn builtins into a property of Engine" as a duplicate?

comment:10 by Tim Graham, 9 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:11 by Preston Timmons <prestontimmons@…>, 9 years ago

Owner: set to Preston Timmons <prestontimmons@…>
Resolution: fixed
Status: newclosed

In 655f5249:

Fixed #17085, #24783 -- Refactored template library registration.

  • Converted the libraries and builtins globals of django.template.base into properties of the Engine class.
  • Added a public API for explicit registration of libraries and builtins.
Note: See TracTickets for help on using tickets.
Back to Top