我试过这个:
{% for i in object %}
{% if i.get(id=1) %}
<img src="{{object.img1.url}}" />
<p><b>Rs {{i.price}}</b></p>
{% endif %}
{% endfor %}
但是,这个错误显示为:
TemplateSyntaxError无法分析来自"i.get(id=1("的剩余部分:"(id=1
我相信您正在尝试获取i
的id,并尝试使用if语句进行检查。所以,试试
{% for i in object %}
{% if i.id == 1 %} <--- Here
<img src="{{ i.img1.url }}" /> <--- Here also i.img1.url not object.img1.url
<p><b>Rs {{i.price}}</b></p>
{% endif %}
{% endfor %}