On Aug 26, 12:44 am, MIL <needb...@gmail.com> wrote:
> Hi guys :o)
>
> Im attempting to create a template tag but I get a strange response.
> it returns "None" where I put the {% if blog_detail %} tag
>
> Here is my template tag
>
> class BlogNode(Node):
>         def __init__(self, user, varname):
>                 self.user, self.varname = user, varname
>
>         def render(self, context):
>                 try:
>                         context[self.varname] = 
> Blog.objects.get(user=self.user)
>                 except ObjectDoesNotExist:
>                         context[self.varname] = False
>
> @register.tag
> def get_blog(parser, token):
>         # {% get_blog for user_object as object_detail %}
>         # {% if blog_detail %} etc...
>         bits = token.contents.split()
>         if len(bits) != 5:
>                 raise TemplateSyntaxError, "get_blog tag takes exactly five
> arguments"
>         if bits[1] != 'for':
>                 raise TemplateSyntaxError, "second argument to get_blog tag 
> must be
> 'for'"
>         if bits[3] != 'as':
>                 raise TemplateSyntaxError, "third argument to get_blog tag 
> must be
> 'as'"
>         return BlogNode(bits[2], bits[4])
>
> Why does it response with a "None" message?
>
> Thanks :o)

Your render() method should return something, even if it's a blank
string. The default value returned by a function in Python is None, so
the template is simply showing this (converted into a string, ie
'None').
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to