如何在 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 页面中的数据?


HUX布斯
浏览 129回答 1
1回答

蓝山帝景

例如:<div>&nbsp; &nbsp; {% for record in records %}&nbsp; &nbsp; &nbsp; &nbsp;{{ record.Roll }}&nbsp; &nbsp; &nbsp; &nbsp;{{ record.Name}}&nbsp; &nbsp; &nbsp; &nbsp;{{ record.Stream}}</div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python