Hi :o)

I am attempting to create a simpler way to create my links. and I
developed this template tag:


class LinkNode(Node):
        def __init__(self, object):
                self.object = object

        def render(self, context):
                model_name = self.object.get_model_name()
                linktext = self.object.get_linktext()
                url = self.object.get_absolute_url()
                if model_name and linktext and url:
                        return '<a href="%s" class="%s">%s</a>' % (url, 
model_name.lower(),
linktext)
                return ''

@register.tag
def create_a_link(parser, token):
        # {% create_a_link to object %}
        bits = token.contents.split()
        if len(bits) != 3:
                raise TemplateSyntaxError, "create_a_link tag takes exactly 
three
arguments"
        if bits[1] != 'to':
                raise TemplateSyntaxError, "second argument to create_a_link tag
must be 'to'"
        return LinkNode(bits[2],)


But I get this error message:
TemplateSyntaxError at /
Caught an exception while rendering: 'unicode' object has no attribute
'get_model_name'

What am I doing wrong????

Is there a simpler and better way to do this job?

I would also like to develop something that can make it simpler to
create tables and lists, but that later on.

Thank you :o)

--~--~---------~--~----~------------~-------~--~----~
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