后端代码:
def js_xianshi(req):
L=[]
#打开一个 文件,将文件的内容的每一行都转成一个字典,再将这些字典存到列表中去f=open(‘c:/Users/Lenovo/PycharmProjects/Try_pitest/media/Pitest3.csv’, ‘r’, encoding=‘utf-8’, newline="\n")
for i in f.readlines():
table = {}
print(’------------------------------------’)
print(i)
#i是str类型,将字符串在有,的地方分割开,然后存到字典中去
table[‘name’] = i.split(’,’)[0]
table[‘percentage’] = i.split(’,’)[1]
table[‘detail’] = i.split(’,’)[2]
L.append(table)
# print(list(i))
# L.append(i)
print("#####################################")
#a=str(table).replace("’",""") 将单引号转为双引号
#a转json
print(L)
return render(req,‘download.html’,{ ‘List’ :L})
前端代码:i是字典类型,提取value
{% for i in List %}
{{i.name}}
{{i.percentage}}
{{i.detail}}
{% endfor %}