Problem With Templatetags

19 views
Skip to first unread message

Showket Bhat

unread,
Jul 28, 2011, 2:17:36 AM7/28/11
to Django users
Hi All,

I am using templatetags to create one tag.. I created the folder
templatetags and created 2 files in it.. __init__.py which is empty
and another temp_tags.py.. where i put one method

temp_tags.py
====================
from django import template
register = template.Library()
register.filter('lower', lower)

def lower(value): # Only one argument.
# "Converts a string into all lowercase"
return value.lower()

=========================
template2.html
=========================

{% load temp_tags %}

This will print my name in lowercase: {{ name|lower }}

============================

I ve not inserted anything in setting.py regarding templatetags and I
am getting this error


=============================

TemplateSyntaxError at /view2/

'temp_tags' is not a valid tag library: Template library temp_tags not
found, tried
django.templatetags.temp_tags,django.contrib.admin.templatetags.temp_tags

Request Method: GET
Request URL: http://localhost:8000/view2/
Django Version: 1.3
Exception Type: TemplateSyntaxError
Exception Value:

'temp_tags' is not a valid tag library: Template library temp_tags not
found, tried
django.templatetags.temp_tags,django.contrib.admin.templatetags.temp_tags

Exception Location: /usr/local/lib/python2.6/dist-packages/django/
template/defaulttags.py in load, line 1054
Python Executable: /usr/bin/python
Python Version: 2.6.4

================================

Please Help....

nicolas HERSOG

unread,
Jul 28, 2011, 2:39:05 AM7/28/11
to django...@googlegroups.com
Hi, I m new in django too but i ll try to help you.

In your tem_tag.py can you add : @register.simle_tag just before you def you tag, just like this :

@register.simle_tag
def my_tag():
    return blablabla




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


nicolas HERSOG

unread,
Jul 28, 2011, 2:39:58 AM7/28/11
to django...@googlegroups.com
mistype, it's @register.simple_tag and not @register.simle_tag of course ...

sorry

Showket Bhat

unread,
Jul 28, 2011, 2:51:42 AM7/28/11
to Django users
Thanks For ur Assistance.. But That Dosen't Helped me... Need Some
Other Solution..

nicolas HERSOG

unread,
Jul 28, 2011, 3:02:09 AM7/28/11
to django...@googlegroups.com
Did you create an empty file __init__.pyc in your tag folder ?

On Thu, Jul 28, 2011 at 8:51 AM, Showket Bhat <scorpio...@gmail.com> wrote:
Thanks For ur Assistance.. But That Dosen't Helped me... Need Some
Other Solution..

--

nicolas HERSOG

unread,
Jul 28, 2011, 3:03:57 AM7/28/11
to django...@googlegroups.com
In my tag folder i have __init__.py __init__.pyc myTag.py et myTag.pyc which is empty

Showket Bhat

unread,
Jul 28, 2011, 3:17:31 AM7/28/11
to Django users
yes I have done that..Do i need to put anything in settings.py

Juergen Schackmann

unread,
Jul 28, 2011, 3:31:51 AM7/28/11
to django...@googlegroups.com
have you added the application that holds your template tag to settings.py?

bruno desthuilliers

unread,
Jul 28, 2011, 4:16:20 AM7/28/11
to Django users
On Jul 28, 8:17 am, Showket Bhat <scorpion.sch...@gmail.com> wrote:
> Hi All,
>
> I am using templatetags to create one tag..

Actually (according to your code snippet) a filter.

> I created the folder
> templatetags and created 2 files in it.. __init__.py which is empty
> and another temp_tags.py.. where i put one method

s/method/function/

> temp_tags.py
> ====================
> from django import template
> register = template.Library()
> register.filter('lower', lower)
>
> def lower(value): # Only one argument.
> #       "Converts a string into all lowercase"
>         return value.lower()


If this is your exact real code, you should get a NameError on the
third line, where you try to register your filter function before it's
defined.


Also and FWIW, you don't really need such a filter, just use
{{ name.lower }} in your template.

> I ve not inserted anything in setting.py regarding templatetags and I
> am getting this error
>
> =============================
>
> TemplateSyntaxError at /view2/
>
> 'temp_tags' is not a valid tag library: Template library temp_tags not
> found, tried
> django.templatetags.temp_tags,django.contrib.admin.templatetags.temp_tags

The django app containing your templatetags package needs to be
registered in settings.INSTALLED_APPS.

Showket Bhat

unread,
Jul 28, 2011, 4:19:32 AM7/28/11
to Django users

Thanks A Lot, U know I did the same thing as u said and put it in
Installed APP in settings and It Worked..Dats great..U know I somewre
found on net that there is nothing to deal with settings .py and
tags... Dats rediculas.. Anyways thank you

bruno desthuilliers

unread,
Jul 28, 2011, 4:19:28 AM7/28/11
to Django users
On Jul 28, 8:39 am, nicolas HERSOG <n.her...@gmail.com> wrote:
> Hi, I m new in django too but i ll try to help you.

That's nice from you, but you should possibly read the post you're
answering a bit more carefully:

> In your tem_tag.py can you add : @register.simle_tag just before you def you
> tag, just like this :
>
> @register.simle_tag
> def my_tag():
>     return blablabla


The OP is actually defining a template filter, not tag, so
register.simple_tag is not going to help...

bruno desthuilliers

unread,
Jul 28, 2011, 4:20:48 AM7/28/11
to Django users


On Jul 28, 9:02 am, nicolas HERSOG <n.her...@gmail.com> wrote:
> Did you create an empty file __init__.pyc in your tag folder ?

That's actually a __init__.py (*not* .pyc). And yes, the OP did and
explicitely mentionned it.

bruno desthuilliers

unread,
Jul 28, 2011, 4:21:57 AM7/28/11
to Django users
On Jul 28, 9:03 am, nicolas HERSOG <n.her...@gmail.com> wrote:
> In my tag folder i have __init__.py __init__.pyc myTag.py et myTag.pyc which
> is empty

Err... is this actually 'myTag.py' or 'temp_tags.py' ?

nicolas HERSOG

unread,
Jul 28, 2011, 4:40:36 AM7/28/11
to django...@googlegroups.com

It was just an exemple I gave to Showket, and you'r right, we don t need a __init__.pyc in the templateTag folder. 
I tried to help Showket but i m quite too unexperiment for it yet :)


--
Reply all
Reply to author
Forward
0 new messages