Django string index out of range
Very confused. I have a variable that has 32 items in it, and I'm trying to do a for loop but it's saying "Caught IndexError while rendering: string index out of range"
Any ideas? The variable definitely isn't empty.
{% if photos %}
<ul class=开发者_运维百科"photo-grid">
{% for photo in photos %}
<li>
<img src="{{ photo.images.low_resolution.url }}" />
</li>
{% endfor %}
</ul>
{% else %}
No photos found.
{% endif %}
I believe the problem might be with the photo.images
part of the value. Is images
an array or collection in the photo object? If it is an array, the images.low_resolution
is trying to access the image in the array at the index value of low_resolution
which is probably not what you want (or maybe it is???). You might need to add some logic to loop over the photo.images
rather than trying to access it the way you are now.
See this answer for other info: How to access array elements in a Django template?
精彩评论