python - 无法将列表对象传递到模板瓶中

标签 python web python-2.7 bottle

Bottle 模板有问题。我无法将 python 列表传递给模板。我的代码如下:

@route('/'):
def home():
    return template('home', var=['item1', 'item2'])

这是 home.tpl:

<html>
   <ul>
       #for item in var:
         <li>{{item}}</li>
       #end
   </ul>
</html>

我认为它可以工作,但抛出了 undefined variable “item”的异常。 请告诉我我的错误在哪里?

最佳答案

Bottle 模板语法使用 %不是 # 来标记 python(ish) block :

<html>
   <ul>
       %for item in var:
         <li>{{item}}</li>
       %end
   </ul>
</html>

关于python - 无法将列表对象传递到模板瓶中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16068617/

相关文章:

在光标位置绘制粒子的Javascript将粒子发送到底部

python - 从 C 调用 python hello world 函数,解析字符串参数

django - 使用 apache 编译 mod_wsgi 的问题

python - 尝试从 while 循环返回 python 中的正确整数?

c# - 是否可以为 ASP.Net Web 应用程序类型项目编写使用读/写 .config 的工作代码?

python - fork 运输应用程序在 Django oscar 中没有效果

azure - 标准网站 (Windows Azure) 上的 Crystal Reports

Python识别数字在哪个区间

python - 如何测试 Django CreateView?

python - 迭代与Python中的列表对应的字典键值