我正在构建一个小应用程序,同时测试金字塔/变色龙+MongoDB 到目前为止,我喜欢它,但我遇到了一条死胡同
快速查看我要从类别集合中显示的数据
_id:"category"
themes:Array
0:Object
_id:"theme1"
1:Object
_id:"theme2"
2:Object
_id:"theme3"
user:"username"
主题是mongoengine中嵌入的DocumentListField(但为此,我只需要id)
我研究了如何使用tal:用tal重复我的分类
pt文件
<div class = "category" tal:repeat="c categories">
<h2>${c.id}</h2>
</div>
viewmodel
self.categories = get_category_for_user(user)
我现在想要的是嵌套tal:重复以显示如下结果
<div class = "category" tal:repeat="c categories">
<h2>${c.id}</h2>
<div class="theme" tal:repeat="t themes">
<div class="title">
<a href="/theme/${t.id}">${t.id}</a></div>
</div>
</div>
</div>
问题是获取主题,我需要类别,但我还没有想到如何将循环中使用的类别提取到viewmodel。有没有办法将变量从pt传递到viewmodel py文件?类似于tal:重复t主题(${c.id})? 还是我做的完全错误,有一个简单的方法可以做到
我在前面的问题中找到了我的答案,抱歉打扰了
tal nested dictionary syntax
答案很简单:
不同之处在于第3行重用c变量以获取嵌套数据
金字塔太棒了
相关问题 更多 >
编程相关推荐