Opened 4 years ago

Closed 4 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: master
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 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:2 Changed 4 years ago by andrei kulakov

Owner: changed from nobody to andrei kulakov
Status: newassigned

comment:3 Changed 4 years ago by Preston Timmons

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 Changed 4 years ago by andrei kulakov

@preston, no problem, unassigning myself..

comment:5 Changed 4 years ago by andrei kulakov

Owner: andrei kulakov deleted
Status: assignednew

comment:6 Changed 4 years ago by andrei kulakov

Cc: andrei.avk@… added

comment:7 Changed 4 years ago by Preston Timmons

Has patch: set

comment:8 Changed 4 years ago by Tim Graham

Patch needs improvement: set

comment:9 Changed 4 years ago by Tim Graham

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

comment:10 Changed 4 years ago by Tim Graham

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:11 Changed 4 years ago by Preston Timmons <prestontimmons@…>

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