<div dir="ltr">Hi there,<br><br>I'm developing web applications in Python, so I use a templating system to produce HTML.<br><br>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.<br>
<br>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).<br>
<br>So my question is: is there any way to get clear error messages with a Python templating system?<br><br>I welcome both suggestion on how to get those with Cheetah (or Mako), and suggestions about alternative templating systems that provide better error messages.<br>
<br>Thanks,<br><br>Tom<br><br>-----<br><br># foo.mako:<br>hello ${data}<br><br>>>> print mako.template.Template(filename="foo.mako").render(data="world")<br>hello world<br><br>>>> print mako.template.Template(filename="foo.mako").render(dataerr="world")<br>
Traceback (most recent call last):<br>  File "<stdin>", line 1, in <module><br>  File "/usr/lib/python2.5/site-packages/Mako-0.1.10-py2.5.egg/mako/template.py", line 114, in render<br>    return runtime._render(self, self.callable_, args, data)<br>
  File "/usr/lib/python2.5/site-packages/Mako-0.1.10-py2.5.egg/mako/runtime.py", line 287, in _render<br>    _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data))<br>  File "/usr/lib/python2.5/site-packages/Mako-0.1.10-py2.5.egg/mako/runtime.py", line 304, in _render_context<br>
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)<br>  File "/usr/lib/python2.5/site-packages/Mako-0.1.10-py2.5.egg/mako/runtime.py", line 337, in _exec_template<br>    callable_(context, *args, **kwargs)<br>
  File "foo_mako", line 19, in render_body<br>  File "/usr/lib/python2.5/site-packages/Mako-0.1.10-py2.5.egg/mako/runtime.py", line 91, in __str__<br>    raise NameError("Undefined")<br>NameError: Undefined<br>
<br></div>