如何访问模板中的下划线起始属性或错误变量和属性在 Django 2.0 中可能不以下划线开头?

辛格先生

我有这样的 ElasticSearch 迭代数据:

(Pdb) data[0]
     {'_index': 'publishserdata-index',
      '_type': 'publishser_data_index', 
      '_id': '35', '_score': 1.0, 
      '_source': {'publisher': 'Admin',
                 'department': 'IT', 
                 'subdepartment': 'Full Stack Developer',
                 'inventory_ID': 'IT003',
                 'title': 'Why Should I Use Celery?', }}

我想获得出版商、部门、标题数据。

当我在模板中迭代值时:-

{% for d in data %}
       {{d._source.publisher}}/error
{% endfor %}
丹尼尔罗斯曼

正如该代码所示,data[0]是一个字典。因此,您可以使用普通的 dict 语法来访问其内容:data[0]['_source']等。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章