Django循环–删除最后一个逗号 [英] Django loop – remove last comma

查看:46
本文介绍了Django循环–删除最后一个逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了以下循环,但是需要删除最后一项的逗号(这是为cycle2复制JSON数组)

I have the following loop set up, but need to remove the comma on the last item (it's to replicate a JSON array for cycle2)

{% for product_in_series in series.get_products %}{%spaceless%}
    {% with product_in_series.product as product %}
    {%if not forloop.first%}
            "<img src='{% version product.get_overview 'page_image' %}'>",
    {%endif%}
    {% endwith %}
{%endspaceless%}{% endfor %}

干杯,R

推荐答案

这怎么办?

{% for product_in_series in series.get_products %}{%spaceless%}
    {% with product_in_series.product as product %}
    {%if not forloop.first%}
        "<img src='{% version product.get_overview 'page_image' %}'>"
        {%if not forloop.last%},{%endif%}
    {%endif%}
    {% endwith %}
{%endspaceless%}{% endfor %}

这篇关于Django循环–删除最后一个逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆