Wednesday, March 30, 2011

django custom template tags: how to send to (parser, token)

I've just started using custom tags and need some help parsing info
to:

@register.tag
def friends_of(parser, token):
tag_name, user_var = token.split_contents()
return FriendsOfNode(user_var)

class FriendsOfNode(template.Node):
def __init__(self, user_var):
self.user_var = template.Variable(user_var)

def render(self, context):
user = self.user_var.resolve(context)
context.update({'friends': Friendship.objects.friends_of(user,
True)})
return u''

I tried:

friends: {% friends_of {{ user }} %}

output:

ValueError at /friends/

too many values to unpack

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment