开发者

Strange (atleast for me) behavior in Django template

开发者 https://www.devze.com 2023-01-01 01:15 出处:网络
The following code snippet in a Django template (v 1.1) doesn\'t work. {{ item.vendors.all.0 }} ==> r开发者_如何学编程eturns \"Test\"

The following code snippet in a Django template (v 1.1) doesn't work.

{{ item.vendors.all.0 }} ==> r开发者_如何学编程eturns "Test"

but the following code snippet, doesn't hide the paragraph!

{% ifnotequal item.vendors.all.0 "Test" %}
<p class="view_vendor">Vendor(s): {{item.vendors.all.0}} </p><br />
{% endifnotequal %}

Any tips on what's wrong?

Thanks.


item.vendors.all.0 doesn't return "Test": It returns a vendor object, which gives "Test" when converted to a string. If you just compare the object with "Test", it will never be equal.

Try converting the object to a string before comparing:

{% ifnotequal item.vendors.all.0|stringformat:"s" "Test" %}
0

精彩评论

暂无评论...
验证码 换一张
取 消