Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#21526 closed Uncategorized (invalid)

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

Reported by: oubiga 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 Changed 21 months ago by bmispelon

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 21 months ago by oubiga

Hi,
You are absolutely right!
Thanks.

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