Django - {%if%}块中的模板标记 [英] Django -- Template tag in {% if %} block
问题描述
{'title':title,'sources':sources})
在HTML模板中,我想完成以下几行:
{%for source来源%}
< tr>
< td> {{source}}< / td>
< td>
{%if title == {{source}}%}
刚刚!
{%endif%}
< / td>
< / tr>
{%endfor%}
但是,以下文本块会导致错误:
/ admin / start /
中的TemplateSyntaxError无法解析余数:'{{'from'{{'
...与 {%if title == {{source}} %}
以红色突出显示。
您不应该使用双括号 {{}}
语法 if
或 ifequal
语句,你可以只需访问变量,就像在正常的python中一样:
{%if title == source%}
。 ..
{%endif%}
I have the following dictionary passed to a render function, with sources being a list of strings and title being a string potentially equal to one of the strings in sources:
{'title':title, 'sources':sources})
In the HTML template I'd like to accomplish something among the lines of the following:
{% for source in sources %}
<tr>
<td>{{ source }}</td>
<td>
{% if title == {{ source }} %}
Just now!
{% endif %}
</td>
</tr>
{% endfor %}
However, the following block of text results in an error:
TemplateSyntaxError at /admin/start/
Could not parse the remainder: '{{' from '{{'
...with {% if title == {{ source }} %}
being highlighted in red.
You shouldn't use the double-bracket {{ }}
syntax within if
or ifequal
statements, you can simply access the variable there like you would in normal python:
{% if title == source %}
...
{% endif %}
这篇关于Django - {%if%}块中的模板标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!