I would like to add an optional include in a bottle template.
Unfortunately this does not work as expected:
<foo>
% include(required_view)
<%
try:
include(optional_view)
except NameError:
pass
%>
</foo>
It does indeed make the optional import, but it stops after that.
(So </foo> is missing from the result.)
I would like to allow for the variable optional_view to be undefined.
Always adding 'optional_view': None to the context would be annoying.
(Not to mention always adding an empty view.)
The end keyword was missing. This works:
The right answer came from this followup question.
Quote from the Bottle documentation about embedded Python code: