最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

django - TemplateSyntaxError : Could not parse the remainder - Stack Overflow

programmeradmin5浏览0评论

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.

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.

Share Improve this question edited Mar 24 at 5:53 Devasya Dave asked Mar 24 at 5:34 Devasya DaveDevasya Dave 32 bronze badges 1
  • Isn't your thumbnail a template tag? {{ thumbnail i.image 320x260 }} does not make any sense. – willeM_ Van Onsem Commented Mar 24 at 6:42
Add a comment  | 

1 Answer 1

Reset to default 1

{{ 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 %}
发布评论

评论列表(0)

  1. 暂无评论