如何从列表中选择第一个项目 [英] How to select the first item from a list
本文介绍了如何从列表中选择第一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下
code> {%如果照片%}
{%照片中的照片%}
{%thumbnail photo.photo100x100crop =centeras im%}
< ; img src ={{im.url}}alt =用户的照片data-ajax ={%url'photo_increase_view'pk = photo.id%}/>
{%endthumbnail%}
{%endfor%}
{%endif%}
如何选择并显示列表中的第一张照片?
解决方案
您可以访问第一张照片元素使用 .0
:
将其与 with
标签(以最小化更改):
{%if photos%}
{%with photo = photos.0%}
{%thumbnail photo.photo 100x100crop =centeras im%}
< img src ={{im.url}}alt =用户的照片data-ajax ={%url'photo_increase_view'pk = photo。 id%}/>
{%endthumbnail%}
{%endwith%}
{%endif%}
I have the following for
loop that spits out all photos in a list:
{% if photos %}
{% for photo in photos %}
{% thumbnail photo.photo "100x100" crop="center" as im %}
<img src="{{ im.url }}" alt="User's photos" data-ajax="{% url 'photo_increase_view' pk=photo.id %}"/>
{% endthumbnail %}
{% endfor %}
{% endif %}
How can I just select and display the first photo in the list?
解决方案
You can access the first element using .0
:
Combine it with with
tag (to minimize changes):
{% if photos %}
{% with photo=photos.0 %}
{% thumbnail photo.photo "100x100" crop="center" as im %}
<img src="{{ im.url }}" alt="User's photos" data-ajax="{% url 'photo_increase_view' pk=photo.id %}"/>
{% endthumbnail %}
{% endwith %}
{% endif %}
这篇关于如何从列表中选择第一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文