from mako.template import Template
from mako.exceptions import html_error_template
x = Template("""
X:
<% raise Exception('<span style="color:red">Foobar</span>') %>
""")
try:
x.render()
except:
# <h3>Exception: <span style="color:red">Foobar</span></h3>
print html_error_template().render(full=False, css=False)