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.imagespart of the value. Isimagesan array or collection in the photo object? If it is an array, theimages.low_resolutionis trying to access the image in the array at the index value oflow_resolutionwhich is probably not what you want (or maybe it is???). You might need to add some logic to loop over thephoto.imagesrather 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?