Re: "'str' object has no attribute 'source'" for a simple test tag

2010-06-17 Thread Daniel Roseman
On Jun 17, 4:11 pm, Derek  wrote:
> Running Django 1.2.1 with Python 2.6
>
> I am trying to create a simple test tag (the more complex ones are not
> working either...).
>
> In the templatetags directory, I have this code in the my_tags.py file:
>
> from django import template
> register = template.Library()
>
> @register.tag
> def foo(eggs=None, spam=None):
>     return "foo"
> foo.is_safe = True
>
> And in the template file that uses it I have:
>
> {% load my_tags %}
> {% foo %}
>
> However, when I try and load the template file, I get a:
>
> Exception Type: AttributeError at /path/to/url
> Exception Value: 'str' object has no attribute 'source'
>
> error, and the full trace path includes no references to my source file(s).
>
> What (presumably obvious) mistake am I making?
>
> Thanks
> Derek

With the @register.tag decorator, you need to define a proper template
node class - the decorator goes on the compilation function that
returns that node. You want the @register.simple_tag decorator
instead.
--
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-us...@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.



"'str' object has no attribute 'source'" for a simple test tag

2010-06-17 Thread Derek
Running Django 1.2.1 with Python 2.6

I am trying to create a simple test tag (the more complex ones are not
working either...).

In the templatetags directory, I have this code in the my_tags.py file:

from django import template
register = template.Library()

@register.tag
def foo(eggs=None, spam=None):
return "foo"
foo.is_safe = True


And in the template file that uses it I have:

{% load my_tags %}
{% foo %}


However, when I try and load the template file, I get a:

Exception Type: AttributeError at /path/to/url
Exception Value: 'str' object has no attribute 'source'

error, and the full trace path includes no references to my source file(s).

What (presumably obvious) mistake am I making?

Thanks
Derek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.