【问题标题】:Could not parse the remainder: '{{' from '{{'无法解析剩余部分:来自“{{”的“{{”
【发布时间】:2017-05-05 16:30:07
【问题描述】:

我正在尝试创建一个简单的页面,该页面应该显示一个表格。 它假设有几行和几列。但并非每一行都应该有相同数量的列。

这是产生错误的我的 html 代码:

<html>
  {% for count in machine_count %}
        <tr>
            <td>{{ count }}</td>
            <td>Aufzugmotor</td>

            {% for status in statuses %}
                 {{ status.machine_number}}
                {% if count == {{ status.machine_number }} %}
                    <td class="tableCell">
                        <img class="imageClass" src={{ status.src }}>
                    </td>
                {% endif %}
            {% endfor %}
        </tr>
        {% endfor %}
</html>

statuses 是一个模型,machine_number 是一个字符串元组。

我并没有真正理解我所犯的错误。 难道不能在占位符上使用 if-tag 吗?

【问题讨论】:

    标签: python html django parsing if-statement


    【解决方案1】:
    {% if count == {{ status.machine_number }} %}
    

    应该是:

    {% if count == status.machine_number %}
    

    【讨论】:

    • 但它真的是从模型对象中取出信息吗?
    • 因为即使 machine_number 存在,它也不会显示任何内容。所以我认为如果我这样做,它不会获取正确的数据。
    【解决方案2】:

    {{...}} 仅用于将变量内容注入最终输出。如果您在其他情况下使用该变量,请忽略它们。

    【讨论】:

      猜你喜欢
      • 2021-12-20
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 2020-10-10
      • 2021-04-15
      • 2017-09-11
      相关资源
      最近更新 更多