Django模板标记:在条件标记中使用forloop.first标记

Django模板标记:在条件标记中使用forloop.first标记,django,django-templates,formset,detailview,Django,Django Templates,Formset,Detailview,这是我使用django formset和detailview的延续 让我们看看一位客户在6月3日订购了一件商品。如何在6月3日之前获取该商品的最新价格,即2美元 我有以下django模板标记,但它返回$4 {% for cartitem_ in object.model_customercartitem_set.all %} {% for pricerow_ in cart_item.item_name.model_itemprice_set.all %} {% if

这是我使用django formset和detailview的延续

让我们看看一位客户在6月3日订购了一件商品。如何在6月3日之前获取该商品的最新价格,即2美元

我有以下django模板标记,但它返回$4

{% for cartitem_ in object.model_customercartitem_set.all %}
    {% for pricerow_ in cart_item.item_name.model_itemprice_set.all %}
        {% if price_row.timestamp|date:"U" <= object.timestamp|date:"U" %}
            {% if forloop.first %}
                {{ price_row.item_price }}
            {% endif %}
        {% endif %}
    {% endfor %}
{% endfor %}
{object.model\u customercartitem\u set.all%}
{cart\u item.item\u name.model\u itemprice\u set.all%}

{%if price_row.timestamp|date:“U”您错过了一个{%endif%}

{% for cartitem_ in object.model_customercartitem_set.all %}
    {% for pricerow_ in cart_item.item_name.model_itemprice_set.all %}
        {% if price_row.timestamp|date:"U" <= object.timestamp|date:"U" %}
            {% if forloop.first %}
                {{ price_row.item_price }}
            {% endif %}
        {% endif %} <!-- here -->
    {% endfor %}
{% endfor %}
{object.model\u customercartitem\u set.all%}
{cart\u item.item\u name.model\u itemprice\u set.all%}

{%if price_row.timestamp|date:“U”抱歉,我忘记在原始帖子中包含此内容。谢谢。即使经过修改,我仍然无法获得正确的物品价格。我只需打印{{price_row.item_price}而不打印{%if forloop.first%}部分,然后查看输出是什么,然后确定下一步要做什么。我认为应该在视图中而不是在模板中对该逻辑进行编码。模板应该用于计算内容是一种常见的误解。模板实际上应该仅用于以良好的方式呈现内容。谢谢。我尝试在视图中对其进行编码,但没有用当涉及django formset时。