我想在Django模板中始终使用我的变量的正值.变量的符号只是一个文本含义:
{% if qty > 0 %}
  Please, sell {{ qty }} products.
{% elif qty < 0 %}
  Please, buy {{ -qty }} products.
{% endif %}
当然,{{ -qty }}不起作用.
有没有传递包含绝对值的第二个变量的解决方法?像模板过滤器那样将值转换为无符号整数的东西.
谢谢!
我正在循环推车项目,并希望将数量乘以单位价格,如下所示:
{% for cart_item in cart.cartitem_set.all %}
{{cart_item.quantity}}*{{cart_item.unit_price}}
{% endfor %}
有可能做那样的事吗?任何其他方式!谢谢