\u键的Django模板forloop

2024-05-20 19:55:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我的django模板中有json值,我需要为其中的每个值循环

{
    "hits": [
       {
        "_index": "catalog",
        "_type": "mobiles",
        "_id": "2e4d3356-95eb-4cc2-b4be-f75baa55248f",
        "_score": 1,
        "_source": {
            "name": "Apple iPhone 5S 16GB Space Grey",
            "product_score": "109",
            "product_rating": {
                "avg": "5",
                "count": "1"
            }
        }
       }
   ]
}

我应该如何在“\u source”中迭代?

此代码无效:

{% for i in hits.items %}
<div>{{i}}</div>
{% endfor %}

主要的疑问是如何在“\(下划线)”元素中循环


Tags: djangodiv模板idjsonsourceindextype