Custom template tags not loading

498 views
Skip to first unread message

Corey

unread,
Jun 15, 2006, 5:05:06 PM6/15/06
to Django users
Hi All!

I've written a custom template tag, but I get the error:
'reservationtags' is not a valid tag library: Could not load template
library from django.templatetags.reservationtags, No module named
reservationtags

I've looked in the archives and have tried everything I know so far:

1. templatetags directory is in the same level as models.py
2. templatetags has two files: __init__.py and reservationtags.py
3. I ran python manage.py shell, and executed:
from pennysaver.reservations.templatetags import reservationtags
and received no error.
4. reservationtags.py has: register = template.Library() and
register.tag('columnize', do_columnize)

For good measure, here's my code:

from django import template

register = template.Library()

def do_columnize(parser, token):
nodelist = parser.parse(('endcolumnize',))
parser.delete_first_token()

#Get the number of columns, default 1
try:
tag_name, columns, row_class, cell_class =
token.contents.split(None, 3)
except ValueError:
columns = 1

return ColumnizeNode(nodelist, columns)

class ColumnizeNode(template.Node):
def __init__(self, nodelist, columns):
self.nodelist = nodelist
self.columns = columns
self.counter = 1

def render(self, context):
self.counter += 1
if (self.counter > self.columns):
self.counter = 1

if (self.counter == 1):
output = '<tr'
if self.row_class:
output += ' class="%s">' % self.row_class
else:
output += '>'

output += '<td'
if self.cell_class:
output += ' class="%s">' % self.cell_class
else:
output += '>'

output += self.nodelist.render(context)

if (self.counter == self.columns):
output += '</tr>'

return output

register.tag('columnize', do_columnize)


Thanks for any help!

Corey

ivanm...@gmail.com

unread,
Jun 15, 2006, 5:19:55 PM6/15/06
to Django users
make sure your application exists in the project's settings file
INSTALLED_APPS

Don Arbow

unread,
Jun 15, 2006, 5:57:31 PM6/15/06
to django...@googlegroups.com
On Jun 15, 2006, at 2:05 PM, Corey wrote:

>
> Hi All!
>
> I've written a custom template tag, but I get the error:
> 'reservationtags' is not a valid tag library: Could not load template
> library from django.templatetags.reservationtags, No module named
> reservationtags
>
> I've looked in the archives and have tried everything I know so far:
>
> 1. templatetags directory is in the same level as models.py
> 2. templatetags has two files: __init__.py and reservationtags.py
> 3. I ran python manage.py shell, and executed:
> from pennysaver.reservations.templatetags import reservationtags
> and received no error.
> 4. reservationtags.py has: register = template.Library() and
> register.tag('columnize', do_columnize)

The error is probably not in your module (note in the error, django
is appending 'django' to its search path), but in the {% load %} tag
in your template. You didn't specify what your template looks like.
When you code the load, do not include 'templatetags' in the path, so
in your template the load statement should look something like

{% load reservations.reservationtags %}

Don

Corey Oordt

unread,
Jun 15, 2006, 7:23:55 PM6/15/06
to django...@googlegroups.com
Don,

Thanks for the reply. When I put in {% load reservations.reservationtags %} I get:

'reservations.reservationtags' is not a valid tag library: Could not load template library from django.templatetags.reservationtags, No module named reservationtags

Any other ideas?

Thanks,

Corey

Corey Oordt

unread,
Jun 15, 2006, 7:25:15 PM6/15/06
to django...@googlegroups.com
I'm going to bow my head in shame....

I was SURE that I put it there! Thanks for making me look ivan!

Corey

Reply all
Reply to author
Forward
0 new messages