Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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-在模板变量中使用forloop.counter_Python_Html_Django_Templates - Fatal编程技术网

Python DJANGO-在模板变量中使用forloop.counter

Python DJANGO-在模板变量中使用forloop.counter,python,html,django,templates,Python,Html,Django,Templates,我的模板中当前有此变量: {{ product_list.0.image_set.all.0.image.url }} 它成功地给出了产品列表中第一个产品中第一个图像的url 我想要这样的东西: {{ product_list.forloop.counter.image_set.all.0.image.url }} 这样我就可以在for循环中获得product_列表中每个图像的第一个图像。但是上面的代码不起作用。这可能吗?不要使用forloop.counter,逐个对象迭代产品列表: {%

我的模板中当前有此变量:

{{ product_list.0.image_set.all.0.image.url }}
它成功地给出了产品列表中第一个产品中第一个图像的url

我想要这样的东西:

{{ product_list.forloop.counter.image_set.all.0.image.url }}

这样我就可以在for循环中获得product_列表中每个图像的第一个图像。但是上面的代码不起作用。这可能吗?

不要使用
forloop.counter
,逐个对象迭代
产品列表

{% for product in product_list %}
    {{ product.image_set.all.0.image.url }}
{% endfor %}

产品列表中每个产品的第一张图片
你是说?尝试此-
{{product\u list.all.image\u set.0.image.url}