-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b764fc0
commit 804d458
Showing
1 changed file
with
20 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
# coding: utf-8 | ||
from mako.exceptions import TopLevelLookupException | ||
import logging | ||
from mako.exceptions import TopLevelLookupException, html_error_template | ||
from mako.lookup import TemplateLookup | ||
from tornado.web import HTTPError | ||
|
||
from torneira import settings | ||
|
||
|
||
class MakoMixin(object): | ||
|
||
def render_to_template(self, template_name, **context): | ||
assert hasattr(settings, 'TEMPLATE_DIRS'), "Missing TEMPLATE_DIRS config" | ||
|
||
lookup = TemplateLookup(directories=settings.TEMPLATE_DIRS, input_encoding='utf-8', output_encoding='utf-8', default_filters=['decode.utf8']) | ||
lookup = TemplateLookup(directories=settings.TEMPLATE_DIRS, | ||
input_encoding='utf-8', output_encoding='utf-8', | ||
default_filters=['decode.utf8']) | ||
|
||
try: | ||
template = lookup.get_template(template_name) | ||
except TopLevelLookupException: | ||
raise HTTPError(500, "Template %s not found" % template_name) | ||
|
||
return template.render(**context) | ||
context.update({ | ||
'settings': settings, | ||
'url_for': self.reverse_url | ||
}) | ||
|
||
try: | ||
return template.render(**context) | ||
except Exception, e: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
marcelnicolay
Author
Owner
|
||
if settings.DEBUG: | ||
return html_error_template().render() | ||
else: | ||
logging.exception("Template %s could not be rendered" % template_name) | ||
raise e |
If we catch all Exceptions here, the tornado write_error method on RequestHandler won't be called. Maybe we should overwrite write_error on MakoMixin to handle this error? If we do that, the user will be able to specify custom error handlers to catch exceptions.