简体   繁体   English

python mako模板是否支持循环上下文中的connitue / break?

[英]Does python mako template support connitue/break in loop context?

Is it possible to use continue/break in a %control structure loop. 是否可以在%控制结构循环中使用continue / break。

For example: 例如:

% for x in range(1):
 % continue
% endfor

Thanks, 谢谢,

Yes. 是。 You use <% continue %> and <% break %> . 您使用<% continue %><% break %>

Example: 例:

from mako.template import Template 
t = Template( 
""" 
% for i in xrange(5): 
    % if i == 3: 
        <% break %> 
    % endif 
    ${i} 
% endfor 
% for i in xrange(5): 
    % if i == 3: 
        <% continue %> 
    % endif 
    ${i} 
% endfor 
""") 
print t.render() 

Output: 输出:

0 
1 
2 
0 
1 
2 
4 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM