现状
索引\u 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'}]
我创建了以下代码,但如何用“,”分隔层次结构,以更易于理解的方式更容易地显示层次结构?
索引\u 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
对象是list
个set
对象,您可以使用嵌套的for
循环对其进行迭代:输出:
相关问题 更多 >
编程相关推荐