tal嵌套字典语法

2024-09-27 04:28:58 发布

您现在位置:Python中文网/ 问答频道 /正文

使用金字塔时,我的代码如下所示:

class PageData:
    @staticmethod
    def create_data():
        return [
            {   
                'key_1A': 'info1A',
                'key_2A': 'info2A',
                'nested_list_A': [
                    {'nested_key1A': 'nested_val1A'},
                    {'nested_key2A': 'nested_val2A'},
                ],
            },
            {   
                'key_1A': 'info1B',
                'key_2A': 'info2B',
                'nested_list_B': [
                    {'nested_key1B': 'nested_val1B'},
                    {'nested_key2A': 'nested_val2A'},
                ],
            },
            ]

我的html页面代码如下:

^{pr2}$

引用嵌套密钥的正确语法是什么?为了tal:条件语句? 在


Tags: key代码datareturndefcreatelistclass
1条回答
网友
1楼 · 发布于 2024-09-27 04:28:58

在试图弄清楚这一点时,我找到了我的答案。。。在

tal:repeat Syntax: tal:repeat="name expression"

Description: Evaluates "expression", and if it is a sequence, repeats this tag and all children once for each item in the sequence. The "name" will be set to the value of the item in the current iteration, and is also the name of the repeat variable. The repeat variable is accessible using the TAL path: repeat/name and has the following properties:

https://www.owlfish.com/software/simpleTAL/tal-guide.html

<div tal:repeat="a nest_list_A">
<div tal:repeat="b a.nest_list_A">
<span tal:condition="b.nested_key1A">

a成为nest_list_a例如的赋值 b成为a.nested_list_a的赋值,后者将访问它们的键

如果键有值,则塔尔:条件会继续正常操作,否则渲染时将跳过。在

相关问题 更多 >

    热门问题