首页 > 解决方案 > 如何在 Django Server 中解析 HTML 页面中的 CSV 数据?

问题描述

我在views.py中使用了以下函数

 def getdata(request):
    with open('./studata.csv', 'r') as csvfile:
        csv_file_reader = csv.DictReader(csvfile)
        records = list(csv_file_reader)
        count = len(records)
    return render(request,'showdata.html',{'records':records})

这是csv文件-

Roll,Name,Stream
11,Bedanta Borah,Non-Medical,
1,Varsha Sharma,Non-Medical,
3,Nancy,Commerce,
4,Akshita,Humanities,

此数据应显示在 showdata.html 中。如何遍历 HTML 页面中的数据?

标签: pythonhtmldjango

解决方案


例如:

<div>
    {% for record in records %}
       {{ record.Roll }}
       {{ record.Name}}
       {{ record.Stream}}
</div>

有关更多信息,请参阅此信息


推荐阅读