templatetag issue

34 views
Skip to first unread message

Daymien

unread,
Jul 29, 2009, 8:57:21 AM7/29/09
to Django users
Hallo,

I created a templatetag, wich I use to display some notes on admin
index template.
With the bildin develop webserver all works fine.

But when I start the apache server with mod_wsgi or mod_python it
won't work:

*********************************************************************
TemplateSyntaxError at /

'note_tags' is not a valid tag library: Could not load template
library from django.templatetags.note_tags, No module named
note.models

Request Method: GET
Request URL: http://bpagate/
Exception Type: TemplateSyntaxError
Exception Value:

'note_tags' is not a valid tag library: Could not load template
library from django.templatetags.note_tags, No module named
note.models

Exception Location: /usr/local/lib64/python2.4/site-packages/django/
template/defaulttags.py in load, line 926
Python Executable: /usr/bin/python
Python Version: 2.4.2
Python Path: ['/usr/lib/python24.zip', '/usr/lib64/python2.4', '/usr/
lib64/python2.4/plat-linux2', '/usr/lib64/python2.4/lib-tk', '/usr/
lib64/python2.4/lib-dynload', '/usr/lib64/python2.4/site-packages', '/
usr/lib64/python2.4/site-packages/Numeric', '/usr/lib64/python2.4/site-
packages/dbus', '/usr/lib64/python2.4/site-packages/gtk-2.0', '/usr/
local/lib64/python2.4/site-packages', '/data2/Eurexc/scripts']
Server time: Mi, 29 Jul 2009 14:50:56 +0200
*********************************************************************

I don't understand the issue esspecially it works with the buildin
webserver!
Who can hep, please?

chefsmart

unread,
Jul 29, 2009, 9:44:13 AM7/29/09
to Django users
I have a similar issue. I have been stuck on this for too long now.
What is happening is that Django is not locating your custom note_tags
template tag in your application's templatetag directory, though I
don't know why.

Try this --- on your production server, copy your note_tags file from
your application's templatetags directory to the directory django/
templatetags

It might work, but this is not a solution, only a workaround.

Let me know how it goes. By the way, what version of Django are you
using?

Regards.

Greg Fuller

unread,
Jul 29, 2009, 9:46:48 AM7/29/09
to Django users
Are you missing a __init__.py in the tags directory?

chefsmart

unread,
Jul 29, 2009, 9:51:28 AM7/29/09
to Django users
In my case, I have the __init__.py just as I do on my development
environment.

Daymien

unread,
Jul 29, 2009, 9:57:03 AM7/29/09
to Django users
I have teh __init__.py in the directory, too.

I use the newest stabel 1.1
So I will try your solution...

Daymien

unread,
Jul 29, 2009, 10:12:10 AM7/29/09
to Django users
Your solution don't work for me yet :-(
I have been copy the note_tags.py to django/templatetags/ and
restartet Apache.
But I got the same issue. Is there anything else to do?

Regards.

chefsmart

unread,
Jul 29, 2009, 10:46:04 AM7/29/09
to Django users
Where is your production setup? Webfaction? VPS?

And which version of Django are you using?

Daymien

unread,
Jul 29, 2009, 2:56:11 PM7/29/09
to Django users
My Setup is on the Intranet of my company (SLES 10 SP2 System with
apache2 and Django 1.1)

chefsmart

unread,
Jul 30, 2009, 3:56:07 AM7/30/09
to Django users
I have a similar discussion running on
http://groups.google.com/group/django-users/browse_frm/thread/989c569d5118980d

But the workaround I posted in post no. 2 above works for me, I don't
know why it didn't for Daymien.

@Daymien: - When trying out my workaround, try to comment out
'django.template.loaders.app_directories.load_template_source' from
your TEMPLATE_LOADERS setting in settings.py

And then let us know.

This is baffling.

Daymien

unread,
Jul 30, 2009, 4:11:43 AM7/30/09
to Django users
Jippii,
I got the solution :-)

I don't no why this problem only appear with mod_python or mod_wsgi
with apache and not with the build in webserver, but now it works!
The problem was that the app were not in the python search path.
So either you include your app to python include path or you change
the import line in your template tag.

********* NOT working Templatetag ***********
from django.template import Library
from note.models import Note

register = Library()

def display_notes():
latest = Note.objects.all().order_by("-added_date")
return {'notes': latest}
display_notes = register.inclusion_tag("show_note.html")
(display_notes)
*************************************************

********* WORKING Templatetag ****************
from django.template import Library
from gateadmin.note.models import Note

register = Library()

def display_notes():
latest = Note.objects.all().order_by("-added_date")
return {'notes': latest}
display_notes = register.inclusion_tag("show_note.html")
(display_notes)
*************************************************

Look especially to the second include line :-)
The solution is to use the full proj. path like:

"from project.app.models import Model"

have fun!

chefsmart

unread,
Jul 30, 2009, 8:57:45 AM7/30/09
to Django users
I had something like INSTALLED_APPS = ( 'my_django_app',) in my
settings.py. I changed it to INSTALLED_APPS =
( 'my_django_project.my_django_app',) and it set things right.
Reply all
Reply to author
Forward
0 new messages