Json 在 html 模板中
Json in html template
我用 bottle 在 html 模板中打印一些 json,所以我在模板中做:
% for rows in url:
<ul>
% for cols in rows[0:2]:
<li>
{{cols}}
</li>
% end
% for req in rows[2:3]:
<li>
{{req}}
</li>
% end
</ul>
% end
结果:
- http://www.adress/
- 1.5
- {'x-xss-protection': '1;模式=块','x-content-type-options':
'nosniff', 'age': '2295260', 'expires': '2017 年 12 月 8 日星期五 08:32:02
格林威治标准时间','vary':'Accept-Encoding','server':'sffe','last-modified':
'Thu, 08 Dec 2016 01:00:57 GMT', 'connection': 'close'}
但我想在列表的最后一项中制作另一个列表,
所以如果我这样做
% for list in req:
{{list}}
% end
我明白了
- x
- -
- x
- s
- s
- ...
有人知道打印列表吗?
你可以只插入一个内循环
...
% for req in rows[2:3]:
% for line in req:
<li>
{{line}}
</li>
% end
% end
如果它始终是最后一项,您也可以循环遍历它
...
% for line in rows[-1]:
<li>
{{line}}
</li>
%end
我用 bottle 在 html 模板中打印一些 json,所以我在模板中做:
% for rows in url:
<ul>
% for cols in rows[0:2]:
<li>
{{cols}}
</li>
% end
% for req in rows[2:3]:
<li>
{{req}}
</li>
% end
</ul>
% end
结果:
- http://www.adress/
- 1.5
- {'x-xss-protection': '1;模式=块','x-content-type-options': 'nosniff', 'age': '2295260', 'expires': '2017 年 12 月 8 日星期五 08:32:02 格林威治标准时间','vary':'Accept-Encoding','server':'sffe','last-modified': 'Thu, 08 Dec 2016 01:00:57 GMT', 'connection': 'close'}
但我想在列表的最后一项中制作另一个列表, 所以如果我这样做
% for list in req:
{{list}}
% end
我明白了
- x
- -
- x
- s
- s
- ...
有人知道打印列表吗?
你可以只插入一个内循环
...
% for req in rows[2:3]:
% for line in req:
<li>
{{line}}
</li>
% end
% end
如果它始终是最后一项,您也可以循环遍历它
...
% for line in rows[-1]:
<li>
{{line}}
</li>
%end