ImportError: No module named template_util

8 views
Skip to first unread message

Tobias

unread,
May 13, 2008, 1:19:04 AM5/13/08
to TurboGears
Hi,

being a "Kid" and TurboGears newbie (with quite some experience in
Python and TAL), I tried a quite simple template:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/
kid/ns#"
py:extends="'master.kid'">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"
py:replace="''"/>
<title>Welcome to TurboGears</title>
</head>
<body>
<div class="main_content">
<pre py:content="template">item</pre>
<div py:if="template == 'item'">
single entry
</div>
<div py:if="template == 'list'">
list of entries
</div>
</div>
</body>
</html>
<!-- vim: set ts=2 sts=2 sw=2 et si :-->


I have a controller method which should point to the proper URL;
however, all I get is the ImportError mentioned above, which is of no
use to me. Of course, I'm totally unaware of a module named
template_util I'd be responsible of; I found one in the kid-0.9.6-
py2.5.egg\kid directory, but this doesn't seem to be found, does it? I
tried to add a kid.pth file, but this didn't help (or I didn't do it
right...).

Is there anything in the standard master.kid (from tg-admin ) I must
match? How can I make my template work? Any hint welcome!

(Python 2.5.1, WinXP, TurboGears 1.0.4.4; Kid 0.9.6)

Btw, I read something about Genshi giving more informative error
messages; thus, it might be better to use Genshi (or, if this is easy
to accomplish, TAL/METAL). Any pointers regarding this?

Thanks a lot,

Tobias

Christoph Zwerschke

unread,
May 13, 2008, 3:40:12 AM5/13/08
to turbo...@googlegroups.com
Tobias schrieb:

> I have a controller method which should point to the proper URL;
> however, all I get is the ImportError mentioned above, which is of no
> use to me. Of course, I'm totally unaware of a module named
> template_util I'd be responsible of;

template_util is an internal module of Kid that normally you needn't
care about. The template looks ok. You probably need to show us the
controller and the full stack trace. Do you have the latest TurboKid
(1.0.4) installed?

> Btw, I read something about Genshi giving more informative error
> messages; thus, it might be better to use Genshi (or, if this is easy
> to accomplish, TAL/METAL). Any pointers regarding this?

Recent Kid versions give much better error messages. The main advantage
of Genshi is better performance. I'm not aware of anybody using TAL with
TurboGears, probably because Kid/Genshi are very similar and in my
opinion easier to use and more straightforward than TAL/METAL.

If you're using TG 1.0, I recommend sticking with Kid and switching to
Genshi when updating to TG 1.1 or 2.0.

-- Chris

Tobias

unread,
May 13, 2008, 5:45:21 AM5/13/08
to TurboGears
Hi, Chris,

thanks for answering.

On 13 Mai, 09:40, Christoph Zwerschke <c...@online.de> wrote:
> Tobias schrieb:
>
> > I have a controller method which should point to the proper URL;
> > however, all I get is the ImportError mentioned above, which is of no
> > use to me. Of course, I'm totally unaware of a module named
> > template_util I'd be responsible of;
>
> template_util is an internal module of Kid that normally you needn't
> care about. The template looks ok. You probably need to show us the
> controller and the full stack trace. Do you have the latest TurboKid
> (1.0.4) installed?

Yep: TurboKid-1.0.4-py2.5.egg

> Recent Kid versions give much better error messages.

Well, here it is:


Page handler: <bound method Root.ma of <myapp.controllers.Root object
at 0x0177DC50>>
Traceback (most recent call last):
File "C:\Interpreter\Python25\lib\site-packages\cherrypy-2.3.0-
py2.5.egg\cherrypy\_cphttptools.py", line 121, in _run
self.main()
File "C:\Interpreter\Python25\lib\site-packages\cherrypy-2.3.0-
py2.5.egg\cherrypy\_cphttptools.py", line 264, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in ma
File "c:\interpreter\python25\lib\site-packages\TurboGears-1.0.4.4-
py2.5.egg\turbogears\controllers.py", line 365, in expose
*args, **kw)
File "<string>", line 5, in run_with_transaction
File "c:\interpreter\python25\lib\site-packages\TurboGears-1.0.4.4-
py2.5.egg\turbogears\database.py", line 405, in sa_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File "c:\interpreter\python25\lib\site-packages\TurboGears-1.0.4.4-
py2.5.egg\turbogears\controllers.py", line 380, in <lambda>
mapping, fragment, args, kw)))
File "c:\interpreter\python25\lib\site-packages\TurboGears-1.0.4.4-
py2.5.egg\turbogears\controllers.py", line 421, in _execute_func
return _process_output(output, template, format, content_type,
mapping, fragment)
File "c:\interpreter\python25\lib\site-packages\TurboGears-1.0.4.4-
py2.5.egg\turbogears\controllers.py", line 87, in _process_output
fragment=fragment)
File "c:\interpreter\python25\lib\site-packages\TurboGears-1.0.4.4-
py2.5.egg\turbogears\view\base.py", line 129, in render
return engine.render(**kw)
File "C:\Interpreter\Python25\lib\site-packages\turbokid-1.0.4-
py2.5.egg\turbokid\kidsupport.py", line 182, in render
tclass = self.load_template(template)
File "C:\Interpreter\Python25\lib\site-packages\turbokid-1.0.4-
py2.5.egg\turbokid\kidsupport.py", line 150, in load_template
mod = _compile_template(package, basename, tfile, classname)
File "C:\Interpreter\Python25\lib\site-packages\turbokid-1.0.4-
py2.5.egg\turbokid\kidsupport.py", line 16, in _compile_template
mod = kid.load_template(tfile, name=classname)
File "C:\Interpreter\Python25\lib\site-packages\kid-0.9.6-py2.5.egg
\kid\__init__.py", line 160, in load_template
store=cache, ns=ns, exec_module=exec_module)
File "C:\Interpreter\Python25\lib\site-packages\kid-0.9.6-py2.5.egg
\kid\importer.py", line 147, in _create_module
raise_template_error(module=name, filename=filename)
File "C:\Interpreter\Python25\lib\site-packages\kid-0.9.6-py2.5.egg
\kid\importer.py", line 143, in _create_module
exec code in mod.__dict__
File "T:\Projekt\My-App\myapp\templates\ma.py", line 5, in <module>
File "T:\Projekt\My-App\myapp\templates\kid.py", line 6, in <module>
ImportError: No module named template_util
Error in code generated from template file 'T:\\Projekt\\My-App\\myapp\
\templates\\ma.kid'

And the controller:

class Root(controllers.RootController):
@expose(template="myapp.templates.welcome")
def index(self):
# return '<h1>Hello World</h1>'
import time
# log.debug("Happy TurboGears Controller Responding For Duty")
flash("Your application is now running")
return dict(now=time.ctime())

...
@expose()
def default(self, *args, **kw):
return "This page is not ready"

...
@expose(template="myapp.templates.ma")
def ma(self, ma_nr=None):
return {'ma_list': [], # dummy data
'template': 'list',
}
from model import Mitarbeiter
if ma_nr is None:
return dict(ma_list=Mitarbeiter.query.all(),
template='list')
else:
return dict(ma=Mitarbeiter.query(ma_nr=ma_nr),
template='item')



> Recent Kid versions give much better error messages. The main advantage
> of Genshi is better performance. I'm not aware of anybody using TAL with
> TurboGears, probably because Kid/Genshi are very similar and in my
> opinion easier to use and more straightforward than TAL/METAL.

Well, that's a matter of taste; knowing Zope and Roundup, I like the
prototype-data-included philosophy, and there are quite useful error
messages...

> If you're using TG 1.0, I recommend sticking with Kid and switching to
> Genshi when updating to TG 1.1 or 2.0.

Ah, ok. Once it works, I'll consider that ;-)

--
Tobias

Christoph Zwerschke

unread,
May 13, 2008, 7:53:37 AM5/13/08
to turbo...@googlegroups.com
Tobias schrieb:

> File "T:\Projekt\My-App\myapp\templates\kid.py", line 6, in <module>

This looks suspicious. Do you have a template named "kid" (as basename,
not as extension!). I can imagine that can cause some problems.

-- Christoph

Tobias

unread,
May 13, 2008, 11:24:43 AM5/13/08
to TurboGears
Yes, I had -- and yes, it did... I had a test template for the built-
in variables and just couldn't think of a better name. After cleaning
this up and restarting the server, it works now.

Ok, so it bit me that templates are compiled to modules -- and are
apparently put in sys.path before the "real" modules.

Thanks a lot,
--
Tobias
Reply all
Reply to author
Forward
0 new messages