Skip to content
Snippets Groups Projects
Commit 8d67633e authored by Mike Bayer's avatar Mike Bayer
Browse files

- html_error_template includes options "full=True", "css=True"

  which control generation of HTML tags, CSS [ticket:39]
parent be1e5339
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,8 @@
stack is properly handled for the def.
- fix to RichTraceback and exception reporting to get template
source code as a unicode object #37
- html_error_template includes options "full=True", "css=True"
which control generation of HTML tags, CSS [ticket:39]
- added the 'encoding_errors' parameter to Template/TemplateLookup
for specifying the error handler associated with encoding to
'output_encoding' [ticket:40]
......
......@@ -148,6 +148,12 @@ Or for the HTML render function:
except:
print exceptions.html_error_template().render()
The `html_error_template` template accepts two options: specifying `full=False` causes only a section of an HTML document to be rendered. Specifying `css=False` will disable the default stylesheet from being rendered.
E.g.:
print exceptions.html_error_template().render(full=False)
The HTML render function is also available built-in to `Template` using the `format_exceptions` flag. In this case, any exceptions raised within the **render** stage of the template will result in the output being substituted with the output of `html_error_template`.
{python}
......
......@@ -166,15 +166,25 @@ ${str(tback.error.__class__.__name__)}: ${str(tback.error)}
def html_error_template():
"""provides a template that renders a stack trace in an HTML format, providing an excerpt of
code as well as substituting source template filenames, line numbers and code
for that of the originating source template, as applicable."""
for that of the originating source template, as applicable.
the template's default encoding_errors value is 'htmlentityreplace'. the template has
two options:
with the full option disabled, only a section of an HTML document is returned.
with the css option disabled, the default stylesheet won't be included."""
import mako.template
return mako.template.Template(r"""
<%!
from mako.exceptions import RichTraceback
%>
<%page args="full=True, css=True"/>
% if full:
<html>
<head>
<title>Mako Runtime Error</title>
% endif
% if css:
<style>
body { font-family:verdana; margin:10px 30px 10px 30px;}
.stacktrace { margin:5px 5px 5px 5px; }
......@@ -185,8 +195,11 @@ def html_error_template():
.sourceline { margin:5px 5px 10px 5px; font-family:monospace;}
.location { font-size:80%; }
</style>
% endif
% if full:
</head>
<body>
% endif
<h2>Error !</h2>
<%
......@@ -221,6 +234,8 @@ def html_error_template():
% endfor
</div>
% if full:
</body>
</html>
% endif
""", output_encoding=sys.getdefaultencoding(), encoding_errors='htmlentityreplace')
......@@ -13,7 +13,8 @@ def suite():
'filters',
'inheritance',
'call',
'cache'
'cache',
'exceptions_'
)
alltests = unittest.TestSuite()
for name in modules_to_test:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment