Python 如何访问模板中的下划线起始属性或Django 2.0中的错误变量和属性不能以下划线开头?
我有如下ElasticSearch迭代数据:Python 如何访问模板中的下划线起始属性或Django 2.0中的错误变量和属性不能以下划线开头?,python,django,
elasticsearch,django-views,django-2.0,Python,Django,
elasticsearch,Django Views,Django 2.0,我有如下ElasticSearch迭代数据: (Pdb) data[0] {'_index': 'publishserdata-index', '_type': 'publishser_data_index', '_id': '35', '_score': 1.0, '_source': {'publisher': 'Admin', 'department': 'IT', 's
(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。因此,您可以使用正常的dict语法来访问其内容:data[0][''u source']
,等等