python - 如何在 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 页面中的数据?
解决方案
例如:
<div>
{% for record in records %}
{{ record.Roll }}
{{ record.Name}}
{{ record.Stream}}
</div>
有关更多信息,请参阅此信息
推荐阅读
- doctrine-orm - Doctrine DiscriminatorMap 子句 Where
- r - 它说我有未提交的更改,但我确实提取了内容,它说我已经是最新的
- r - R中的双重否定
- python - 内存错误 - 错误的双重递归?
- excel - HP ALM Excel 插件 - 通过 VBA 宏登录+映射?
- python - Django - 在多个值的两个列表中进行迭代,仅返回一组迭代
- powershell - 通过删除文件名中 @ 标记之后的所有内容,使用 powershell 重命名文件
- java - 通过 Selenium WebDriver 启动特定 Firefox 配置文件时保留所有原始设置
- python - 如何在 embed.add_field discord.py 中添加 url?
- c# - 使用 void 返回类型并将整数数组作为参数