Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » "'str' object has no attribute 'source'" for a simple test tag [RSS Feed]

#1 June 17, 2010 16:11:38

D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 17, 2010 16:34:20

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


On Jun 17, 4:11 pm, Derek <gamesb...@gmail.com> 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 athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » "'str' object has no attribute 'source'" for a simple test tag [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support