#2556 closed defect (fixed)
simple_tag more capable than docs let on
Reported by: | Owned by: | Malcolm Tredinnick | |
---|---|---|---|
Component: | Documentation | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Opening per this email exchange on django-users:
From: Malcolm Tredinnick On Thu, 2006-08-17 at 04:58 -0700, Karen Tracey wrote: > I've been experimenting with writing some template tags by reading > through the documentation and modifying some existing tags defined by > admin. I've got something like this: > from django import template > register = template.Library() > def paginator_number(request, i, paginator, page_num): > #do stuff, eventually returning str output > paginator_number = register.simple_tag(paginator_number) > This works, and I don't understand why. According to the documentation > (http://www.djangoproject.com/documentation/templates_python/#shortcut...) > a simple tag is supposed to only take one argument. Mine, as you see, > takes four. But it works fine, and somehow the arguments are being > checked, because if I pass in the wrong number I get a > TemplateSyntaxError saying that "paginator_number takes 4 arguments". It's a documentation bug, based on me not reading the code carefully enough (I wrote those docs; my fault entirely). I'll fix it when I get a chance. If you file a ticket and assign it to mtredinnick, that would remind me. [...] > It's convenient not to have to check the arguments myself but I'm > concerned about running into trouble down the line.... Now that I read the code more carefully, it inspects your function (using the inspect.getargspec() function from the Python standard library) and works out the positional arguments that it will take. They are then all accounted for when it processes your tag, including generating the error message syou are seeing. What you are doing is completely future proof. Regards, Malcolm
Thanks much for the quick answer!
Note:
See TracTickets
for help on using tickets.
(In [3772]) Fixed #2556 -- Documented that simple_tag functions can take any number of
arguments, not just one.