简体   繁体   English

金字塔和变色龙ZPT

[英]Pyramid and Chameleon ZPT

I'm new to web development and am trying to make a simple webpage in python using Pyramid. 我是网络开发的新手,我正在尝试使用Pyramid在python中创建一个简单的网页。 I've run into a bit of a snag though when it comes to making template files using Chameleon. 当谈到使用Chameleon制作模板文件时,我遇到了一些麻烦。 What I'm trying to do right now is very simple. 我现在要做的事情很简单。 The view callable returns a list of dictionaries (all dictionaries have same keys just different values). view callable返回一个字典列表(所有字典都有相同的键只是不同的值)。 I want to put these value into a table by looping through each entry in the list. 我想通过循环遍历列表中的每个条目将这些值放入表中。

I'm having a lot of trouble finding out how to do the loop in Chameleon. 我在查找如何在Chameleon中进行循环时遇到了很多麻烦。 Once I have a dictionary I know how to get its values for a given key. 有了字典后,我知道如何获取给定键的值。 If anyone knows of a good tutorial or can just give a quick example it would be much appreciated. 如果有人知道一个好的教程或者只是给出一个快速的例子,那将非常感激。

You need to use "tal:repeat". 你需要使用“tal:repeat”。 If you've passed in "people" to the template, which is a list of dictionaries: 如果您已将“people”传递给模板,该模板是一个词典列表:

<ul>
  <li tal:repeat="person people">${person['firstname']} ${person['lastname']}</li>
</ul>

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

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