在mako python中获取%def引用

在mako python中获取%def引用,python,mako,Python,Mako,是否有一种方法可以使用%def引用,其基本思想是: % if condition_a: % func = %def_a % elif condition_b: % func = %def_b ... etc ... ${func( params )} 是的,像这样: % if condition_a: <% func = def_a %> % elif condition_b: <% func = def_b %> % endif ${func( par

是否有一种方法可以使用%def引用,其基本思想是:

% if condition_a:
%    func = %def_a
% elif condition_b:
%    func = %def_b
... etc ...

${func( params )}
是的,像这样:

% if condition_a:
<% func = def_a %>
% elif condition_b:
<% func = def_b %>
% endif

${func( params )}
%如果条件a:
%elif条件b:
%恩迪夫
${func(params)}
@提米:我不知道你的意思,也许是这个

<% func = some_dict[key] %>
${func( params )}

${func(params)}
您可以将任何Python代码放入
,请参阅mako文档