关于Python的jinjia2的学习和使用
1,
**from jinjia2 import Template
html_template ='''
{% for k,v in dict|dictsort(true,'key')%}
++++内容+++++
{% endfor %}
这个字典的循环使用for k,v in dict|dictsort(true,'key')
若是list的循环则使用for k in list.sort
'''
template = Template(html_template)
html_contents = template.render(per= 数据)**
per是模板中的变量,数据是外部的变量
Template的作用是引入class jinjia2中environment.Template
2,可以加入
**{%if %}
++++内容+++++
{%else %}
++++内容+++++
{% endif %}**
来控制html的标签属性class,这种方式可以部分替换Javascript的方式控制元素
关于jinjia2的知识内容的网页:
https://shansan.top/2019/01/09/Jinja2%E8%AF%AD%E6%B3%95%E5%B0%8F%E8%AE%B0/
https://geek-docs.com/python/python-tutorial/python-jinja.html
在使用html table语言的时候,注意:
<table border="1">
<tr>
<th rowspan=5 >Cell A</th> # rowspan对应的是tr的数目,而不是实际的表格的宽度
</tr> # colspan应该是同理对应格子的数目
<tr>
</tr>
<tr>
<td>Cell A</td>
<td>Cell B</td>
</tr>
</table>
关于render函数的网页:
https://www.cnblogs.com/dear_diary/p/8327839.html