Genshi:嵌套 for 循环

发布于 2024-08-12 03:46:56 字数 539 浏览 6 评论 0原文

我需要使用 Genshi 模板生成 HTML。 Html 基本上是一个很长的带有表格的 html。数据来自一个简单的 CSV,所以,我用 python 读取它,将其放入列表 [] 中,然后调用模板并发送变量(列表)

实际上我通过在模板中执行类似的操作来解决它:

<html>
<?python>
    for i in t:
       for e in tp[i]:
           print "<SOME_HTML_TAGS>"
</?>
</html>

但是,这个想法是使用 Genshi 函数(例如循环等)

我阅读了手册,并且我看到一个简单的 for 是这样完成的:

<li py:for="fruit in fruits">      
I like ${fruit}s                   
</li>    

但是,我如何在循环中执行循环(嵌套 for 循环) )???

I need to generate a HTML using a Genshi template. The Html is, basicaly a very long html with tables. The data comes in a simple CSV, so, i read it with python, i put it into a list[] and then i call the template and send the variable (the list)

Actually i solved it by doing something like this in the template:

<html>
<?python>
    for i in t:
       for e in tp[i]:
           print "<SOME_HTML_TAGS>"
</?>
</html>

But, the idea is to use the Genshi funcions (such as loops, etc)

I read the manual, and I see that a simple for is done like this:

<li py:for="fruit in fruits">      
I like ${fruit}s                   
</li>    

But, how do i do a loop inside a loop (nested for loops)???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

(り薆情海 2024-08-19 03:46:56
<table>
<tr py:for="i in t">      
<td py:for="e in tp[i]">
${e}s
</td>
</tr>
</table>
<table>
<tr py:for="i in t">      
<td py:for="e in tp[i]">
${e}s
</td>
</tr>
</table>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文