﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
2556	simple_tag more capable than docs let on	Karen Tracey <graybark@…>	Malcolm Tredinnick	"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!"	defect	closed	Documentation		normal	fixed			Unreviewed	0	0	0	0	0	0
