How to use “in” statement to check is item in the list or not. If I use:
{% for picture in pictures %}
{% if picture in article.pictures %}
<input type="checkbox" checked="true" name="picture" value="{{ picture.key }}" />
{% else %}
<input type="checkbox" name="picture" value="{{ picture.key }}" />
{% endif %}
<img src='/img?img_id={{ picture.key }}'></img> <br />
{% endfor %}
this is failing with:
TemplateSyntaxError: 'if' statement improperly formatted
on line
{% if picture in article.pictures %}
help?
By default, Django templates do not support full conditional expressions. You can check if one value is “true” with if, or you can check whether two values are equal with
ifequal, etc.Perhaps you can decorate your
pictures in the view before you render the template.Then in the template you can act on the value of that new attribute.