Django -- Template tag in {% if %} block -


i have following dictionary passed render function, sources being list of strings , title being string potentially equal 1 of strings in sources:

{'title':title, 'sources':sources}) 

in html template i'd accomplish among lines of following:

{% source in sources %} <tr> <td>{{ source }}</td> <td> {% if title == {{ source }} %} now! {% endif %} </td> </tr> {% endfor %} 

however, following block of text results in error:

templatesyntaxerror @ /admin/start/ not parse remainder: '{{' '{{' 

...with {% if title == {{ source }} %} being highlighted in red.

you shouldn't use double-bracket {{ }} syntax within if or ifequal statements, can access variable there in normal python:

{% if title == source %} ... {% endif %} 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -