【问题标题】:Python using cgi to fill into html template while template don't know how many will be insertedPython使用cgi填充html模板而模板不知道会插入多少
【发布时间】:2014-11-16 17:02:58
【问题描述】:

首先,我有一个类似的html模板

<p> The first element in list is %s </p>
<p> The second element in list is %s </p>
.......

如果我知道 cgi 脚本中只有两个元素,我可以使用 template % mylist 来填充模板。 但是当我不知道cgi脚本会生成多少元素时,我不知道要在模板中放入多少%s,然后我无法正确填充模板。

根据 cgi 的结果生成模板有什么想法吗?

【问题讨论】:

    标签: python html cgi


    【解决方案1】:

    首先,通常你不应该使用 cgi 而应该使用 wsgi(例如使用烧瓶)。

    那么,如果您有现代模板语言(如 jinja2),通常会有循环结构,因此您可以迭代尽可能多的列表元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-17
      • 2012-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多