Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何访问模板中的下划线起始属性或Django 2.0中的错误变量和属性不能以下划线开头?_Python_Django_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Django Views_Django 2.0 - Fatal编程技术网 elasticsearch,django-views,django-2.0,Python,Django,elasticsearch,Django Views,Django 2.0" /> elasticsearch,django-views,django-2.0,Python,Django,elasticsearch,Django Views,Django 2.0" />

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

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

我有如下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。因此,您可以使用正常的dict语法来访问其内容:
data[0][''u source']
,等等