#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: ...]
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