Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#21526 closed Uncategorized (invalid)

register = template.Library(). Is the instance name just a convention?

Reported by: Pablo Oubiña Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords: register, template, Library
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#code-layout shows:

[... To be a valid tag library, the module must contain a module-level variable named register that is a template.Library instance, in which all the tags and filters are registered. So, near the top of your module, put the following: ...]

if I'm not mistaken, "register" is just a convention. I would be more explicit:

[... To be a valid tag library, the module must contain a module-level variable (by convention named register) that is a template.Library instance, in which all the tags and filters are registered. So, near the top of your module, put the following: ...]

Change History (2)

comment:1 by Baptiste Mispelon, 10 years ago

Resolution: invalid
Status: newclosed

Hi,

The documentation is correct here. Django's template code specifically looks for a variable named register: https://github.com/django/django/blob/master/django/template/base.py#L1286

comment:2 by Pablo Oubiña, 10 years ago

Hi,
You are absolutely right!
Thanks.

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