相关疑难解决方法(0)

在Django模板中乘以-1

我想在Django模板中始终使用我的变量的正值.变量的符号只是一个文本含义:

{% if qty > 0 %}
  Please, sell {{ qty }} products.
{% elif qty < 0 %}
  Please, buy {{ -qty }} products.
{% endif %}
Run Code Online (Sandbox Code Playgroud)

当然,{{ -qty }}不起作用.

有没有传递包含绝对值的第二个变量的解决方法?像模板过滤器那样将值转换为无符号整数的东西.

谢谢!

django django-templates

8
推荐指数
2
解决办法
4446
查看次数

乘以django模板

我正在循环推车项目,并希望将数量乘以单位价格,如下所示:

{% for cart_item in cart.cartitem_set.all %}
{{cart_item.quantity}}*{{cart_item.unit_price}}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

有可能做那样的事吗?任何其他方式!谢谢

python django django-templates

8
推荐指数
3
解决办法
2万
查看次数

标签 统计

django ×2

django-templates ×2

python ×1