相关疑难解决方法(0)

Django - {%if%}块中的模板标记

我将以下字典传递给渲染函数,源是字符串列表,标题是一个字符串,可能等于源中的一个字符串:

{'title':title, 'sources':sources})
Run Code Online (Sandbox Code Playgroud)

在HTML模板中,我想在以下几行中完成一些事情:

{% for source in sources %}
  <tr>
    <td>{{ source }}</td>
    <td>
      {% if title == {{ source }} %}
        Just now!
      {% endif %}
    </td>
  </tr>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

但是,以下文本块会导致错误:

TemplateSyntaxError at /admin/start/
Could not parse the remainder: '{{' from '{{'
Run Code Online (Sandbox Code Playgroud)

......以{% if title == {{ source }} %}红色突出显示.

django templates django-templates

32
推荐指数
3
解决办法
9万
查看次数

标签 统计

django ×1

django-templates ×1

templates ×1