Getting clear error messages with a Python templating system?
tom.machinski at gmail.com
Tue Jul 22 00:29:27 CEST 2008
I'm developing web applications in Python, so I use a templating system to
We're dealing with heavy traffic here, so my original choice was the fast
and efficient Cheetah. The main problem is that Cheetah doesn't provide
clear error messages. Even in the best cases, you only get some indication
of the nature of the error ("TypeError: 'str' object is not callable") but
you can't see the code where the error occurs. You can't even know the
approximate region of the template code where the problem originates.
So I tried another templating system, the newer and equally efficient Mako.
Again, same problem. It should be noted that both Cheetah and Mako compile
themselves to an intermediary Python file. This Python file is what's
actually running, so that's where the error originates. This is very
efficient, but also severely hinders debugging (see below for example of
what a very simple error on a very short Mako template generates).
So my question is: is there any way to get clear error messages with a
Python templating system?
I welcome both suggestion on how to get those with Cheetah (or Mako), and
suggestions about alternative templating systems that provide better error
>>> print mako.template.Template(filename="foo.mako").render(data="world")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
line 114, in render
return runtime._render(self, self.callable_, args, data)
line 287, in _render
_render_context(template, callable_, context, *args,
line 304, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
line 337, in _exec_template
callable_(context, *args, **kwargs)
File "foo_mako", line 19, in render_body
line 91, in __str__
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list