djangodjango-templateseasy-thumbnails

TemplateSyntaxError : Could not parse the remainder


Using easy-thumbnails package. Getting the error for the template file below. Cant seem to figure out what the syntax issue is. i.image is of type ImageFileField

**Could not parse the remainder: ' i.image 320x260' from 'thumbnail i.image 320x260' **

 {% for i in image_page.object_list %}
                <div class="col-6 mb-4 grid-item" style="display: none;">
                    <!-- Image thumbnail for gallery -->
                    <div>
                        <img class="img img-responsive" src=
                                " {% if i.image.thumbnail != null %}
                                    {{ i.image.thumbnail }}
                                  {% else %}
                                    {{ thumbnail i.image 320x260 }}
                                {% endif %} " alt="{{ lot.product.title }}"
                            data-toggle="modal" data-target="#lightboxModal" data-image-url="{{ i.image.url }}" data-pk="{{ i.pk }}"
                            style="cursor: pointer;">
                            {% comment %} object-fit: contain; background-color: #f5f5f5; {% endcomment %}
                    </div>
                </div>
                {% endfor %}

Trying to conditionally render image thumbnail if already available in object or generate and save it if the thumbnail is not available.


Solution

  • {{ thumbnail i.image 320x260 }} makes not much sense, you are introducing a variable in the template, but now there are three: thumbnail, i.image and 320x260, and the last one for example is not a valid variable name nor Python literal.

    You use the {% thumbnail %} template tag and thus work with:

    {% thumbnail i.image 320x260 %}