#24586 closed Uncategorized (invalid)
@register.inclusion_tag fails to work on decorated function
Reported by: | Chris Jerdonek | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.7 |
Severity: | Normal | Keywords: | template, inclusion_tag, custom tag, decorator |
Cc: | chris.jerdonek@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When defining custom tags, the @register.inclusion_tag
does not seem to work when applied to a decorated function. For example--
@register.inclusion_tag('template.html', takes_context=True) @my_decorator def my_tag(context, arg): # Code
However, I found that if name='my_tag'
is added to the inclusion_tag()
call, then it worked. This wasn't easy to figure out and doesn't seem to be documented. It just silently failed with no easy way to troubleshoot. It seems like the tag should work without needing to add the name
argument.
Change History (4)
comment:1 by , 10 years ago
Cc: | added |
---|
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
I can see how this would be confusing, but I'm not sure it's a Django problem.
The key to fixing your example is making sure your decorator uses
functools.wraps
. This will carry through the__name__
attribute from the originalmy_tag
function. Otherwise, that piece of information is lost and the tag will be registered with whatever the name is of the inner function in your decorator.