如何在bottle的模板中格式化和显示list里面的set?
How to format and display set inside a list in bottle's template?
现状
index_template.tpl
{{links}}
输出结果
[{'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html', 'https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf', 'https://www.youtube.com/user/OreillyMedia', 'https://www.safaribooksonline.com/?utm_medium=content&utm_source=oreilly.com&utm_campaign=lgen&utm_content=20170601+nav'}, {'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html'}, {'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html', 'https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf', 'https://www.youtube.com/user/OreillyMedia'}]
我创建了下面的代码,但是如何通过用“,”分隔来更容易地以更易于理解的方式显示层次结构?
index_template.tpl
<html>
<ul>
%for item in links:
<li>{{item}}</li>
%end
</ul>
</html>
输出结果
・{'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html', 'https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf', 'https://www.youtube.com/user/OreillyMedia', 'https://www.safaribooksonline.com/?utm_medium=content&utm_source=oreilly.com&utm_campaign=lgen&utm_content=20170601+nav'}
・{'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html'}
・{'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html', 'https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf', 'https://www.youtube.com/user/OreillyMedia'}
您的 links
对象是 set
的 list
,您可以使用嵌套的 for
循环对其进行迭代:
<html>
<ul>
% for link in links:
% for item in link:
<li>{{item}}</li>
% end
% end
</ul>
</html>
输出:
- https://www.safaribooksonline.com/?utm_medium=content&utm_source=oreilly.com&utm_campaign=lgen&utm_content=20170601+nav
- https://www.youtube.com/user/OreillyMedia
- http://www.oreilly.com/about/editorial_independence.html
- http://www.oreilly.com/careers/
- https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf
- http://www.oreilly.com/careers/
- http://www.oreilly.com/about/editorial_independence.html
- https://www.youtube.com/user/OreillyMedia
- http://www.oreilly.com/careers/
- http://www.oreilly.com/about/editorial_independence.html
- https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf
现状
index_template.tpl
{{links}}
输出结果
[{'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html', 'https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf', 'https://www.youtube.com/user/OreillyMedia', 'https://www.safaribooksonline.com/?utm_medium=content&utm_source=oreilly.com&utm_campaign=lgen&utm_content=20170601+nav'}, {'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html'}, {'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html', 'https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf', 'https://www.youtube.com/user/OreillyMedia'}]
我创建了下面的代码,但是如何通过用“,”分隔来更容易地以更易于理解的方式显示层次结构?
index_template.tpl
<html>
<ul>
%for item in links:
<li>{{item}}</li>
%end
</ul>
</html>
输出结果
・{'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html', 'https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf', 'https://www.youtube.com/user/OreillyMedia', 'https://www.safaribooksonline.com/?utm_medium=content&utm_source=oreilly.com&utm_campaign=lgen&utm_content=20170601+nav'}
・{'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html'}
・{'http://www.oreilly.com/careers/', 'http://www.oreilly.com/about/editorial_independence.html', 'https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf', 'https://www.youtube.com/user/OreillyMedia'}
您的 links
对象是 set
的 list
,您可以使用嵌套的 for
循环对其进行迭代:
<html>
<ul>
% for link in links:
% for item in link:
<li>{{item}}</li>
% end
% end
</ul>
</html>
输出:
- https://www.safaribooksonline.com/?utm_medium=content&utm_source=oreilly.com&utm_campaign=lgen&utm_content=20170601+nav
- https://www.youtube.com/user/OreillyMedia
- http://www.oreilly.com/about/editorial_independence.html
- http://www.oreilly.com/careers/
- https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf
- http://www.oreilly.com/careers/
- http://www.oreilly.com/about/editorial_independence.html
- https://www.youtube.com/user/OreillyMedia
- http://www.oreilly.com/careers/
- http://www.oreilly.com/about/editorial_independence.html
- https://cdn.oreillystatic.com/pdf/oreilly_high_performance_organizations_whitepaper.pdf