Hi. I have somewhat stupid problem with, as a title says, an if
statement in for
loop.
I'm trying to list all users in a <select>
, so admin can select one author for an article.
I have something like this:
<select class="form-control select2" id="article-author" name="author">
<option value="0" {% if article.author == "0" %}selected{% endif %}>- Select author -</option>
{% for user in users %}
<option value="{{ user.id }}" {% if article.author == user.id %}selected{% endif %} >{{ user.username }}</option>
{% endfor %}
</select>
This code seems to fail on if
statement inside the for
loop. Removing it, makes template to render.
I know this is kinda stupid error, but I'm looking at it for over half an hour, and I can't find my mistake. Could you, please, point it out?
PS. I have a feeling that code-block marking syntax does not work properly here, so here is an gist - https://gist.github.com/LMSzor/57ab3f5be72277c8530779ad56b0f795