You want to catch mako.exceptions.SyntaxException
.
This code works for me:
@bottle.route('/hello')
def hello():
try:
return bottle.mako_template('hello')
except mako.exceptions.SyntaxException as exx:
return 'mako exception: {}\n'.format(exx)
EDIT: Per your comment, here are some pointers on how to install this globally. Install a bottle plugin that wraps your functions in the mako.exceptions.SyntaxException try block.
Something along these lines:
@bottle.route('/hello')
def hello():
return bottle.mako_template('hello')
def catch_mako_errors(callback):
def wrapper(*args, **kwargs):
try:
return callback(*args, **kwargs)
except mako.exceptions.SyntaxException as exx:
return 'mako exception: {}\n'.format(exx)
return wrapper
bottle.install(catch_mako_errors)