python - PYTHON:我正在尝试从 XML 文件中读取不同的值并发送到 Django Html 模板
问题描述
我已经阅读了 xml 值,但我认为我用来存储数据的方式是错误的。我需要存储一个列表、一个字典或字典列表一些值,然后发送到 HTML 模板并呈现一个包含所有值的 HTML 表:
这应该是结果,下面的代码是我实际从 XML 读取值的方式
for files in file_in_path:
fileP = os.path.join(path,files)
tree = ET.parse(fileP)
roots = tree.getroot()
for x in roots.findall('DatiGeneraliDocumento'): //node of xml file that i need to read
tipdoc = x.find('TipoDocumento').text //all the data
numdoc = x.find('Numero').text
datadoc = x.find('Data').text
mydict = {"tipdoc":item,"numdoc":numdoc,"datadoc":datadoc} //then i'm trying to save in dict
liste.append(mydict)//and append all to a list
context = {"data":liste}
返回(响应,“page.html”,上下文)
当我在我的 html 页面中并尝试使用 django 格式语言“{{ data }}”打印结果时,他会打印出一个值而不是所有值,但是如果在 python 文件中我打印出我的列表,他会打印出所有列表。将所有值存储在所有 xml 文件中然后在 html 表中打印出来的最佳方法是什么?
解决方案
推荐阅读
- c# - 实体框架 - 上传具有特定验证 c# 的多个实体
- c - c中的卷曲替代品
- ruby-on-rails-5 - rails 5 simple_form 错误后将输入类型从选择更改为字符串
- ios - 我可以使用 Apple 开发者证书作为 SSL 服务器证书吗
- go - Go viper .yaml 值环境变量覆盖
- shell - 查找有效和无效记录 CSV 文件的脚本
- entity-framework - 实体框架:在多租户应用程序中每个租户拥有一个数据库时首次访问延迟
- go - 使用 aws-sdk go 从 COS 读取文件
- r - 仅使用另一列中的部分内容填充新列
- xml - Powerbuilder 使用 BasicAuthentication 调用 WebService