simple_tag and takes_context

196 views
Skip to first unread message

Julien

unread,
Feb 28, 2008, 12:58:58 AM2/28/08
to Django users
Hi,

I would like to access the context from simple tag, like this:

@register.simple_tag(takes_context=True)
def my_tag(context):
whatever = resolve_variable('whatever', context)
return 'blabla'

But that doesn't work, I get the error: "simple_tag() got an
unexpected keyword argument 'takes_context'"

Is takes_context only for inclusion tags?
I found this ticket (http://code.djangoproject.com/ticket/1105), which
deals with that issue and whose status is "Accepted"...

Any idea?

Cheers!

Julien

Malcolm Tredinnick

unread,
Feb 28, 2008, 1:38:14 AM2/28/08
to django...@googlegroups.com

On Wed, 2008-02-27 at 21:58 -0800, Julien wrote:
> Hi,
>
> I would like to access the context from simple tag, like this:
>
> @register.simple_tag(takes_context=True)
> def my_tag(context):
> whatever = resolve_variable('whatever', context)
> return 'blabla'
>
> But that doesn't work, I get the error: "simple_tag() got an
> unexpected keyword argument 'takes_context'"
>
> Is takes_context only for inclusion tags?

That is correct. One day we'll add support for simple tag. In the
meantime, it's not that difficult to just write a quick tag without
using the shortcut. See the examples in django/templates/defaulttags.py

Regards,
maclolm

--
I don't have a solution, but I admire your problem.
http://www.pointy-stick.com/blog/

Reply all
Reply to author
Forward
0 new messages