我正在尝试为Python使用Chameleon模板(它基于zopetal/METAL语言)。此简单模板引发错误(dic
是列表中的字典):
<tr tal:repeat="dic myitems">
<span tal:omit-tag="" tal:repeat="pair dic.items()">
<td tal:content="pair[1 if dic.index else 0]"></td>
</span>
</tr>
AttributeError: 'dict' object has no attribute 'index'
- Expression: "pair[1 if dic.index else 0]"
- Filename: <string>
- Location: (line 21: col 33)
- Arguments: repeat: {...} (0)
dic: {...} (11)
with_nginx_distribution: <list - at 0x7f30b34b20e0>
pair: <tuple - at 0x7f30b36c7b90>
css: \n.tabs {\n position: relative; \n min-height: 20...
target_language: <NoneType - at 0x7f30b46ade00>
我试过dic.index
,dic.item.index
,repeat.index
,repeat.item.index
但它们看起来都不对。访问循环项索引的正确语法是什么
文档已过时,右表达式为
repeat['variable'].index
,如下所示:相关问题 更多 >
编程相关推荐