【问题标题】:Could not parse the remainder无法解析剩余部分
【发布时间】:2011-04-03 12:24:19
【问题描述】:

我想比较 num 和 {{buildSummary_list.number}},但为什么它不起作用? 我得到了一个错误

Could not parse the remainder: '{{buildSummary_list.number}}' from '{{buildSummary_list.number}}'"...

{% for num in buildSummary_list.paginator.page_range %}
    {% ifequal num {{buildSummary_list.number}} %}
        <b>{{num}}</b>
    {% endifequal %}
    {% ifnotequal num {{buildSummary_list.number}} %}
        <a href="?page={{num}}"><b>{{num}}</b></a>
    {% endifnotequal %}

{% endfor %}

我想让分页生效: 前 3 4 5 6 >> 下一个

我的代码可以运行,能做到这个效果吗? 谢谢:D

【问题讨论】:

    标签: django django-templates


    【解决方案1】:

    无法解析余数:'>0' from 'forloop.counter>0'

    我收到了这个错误!!!

    如果它是 TemplateSyntaxError 则只需更正代码之间的空格 例如:

    (错误语句){% if forloop.counter|divisibleby:3 and forloop.counter>0 而不是 forloop.last %}

    (正确的语句){% if forloop.counter|divisibleby:3 and forloop.counter > 0 而不是 forloop.last %}
    (forloop.counter > 0) 之间的空间

    这对我有用

    【讨论】:

    • 这与问题没有直接关系,但它给出了同样的错误。我有同样的问题,这很有帮助。因此,我竖起大拇指。
    【解决方案2】:
    django 2.2 relative URL
    
    **Correct**
    
    <a href="{% url 'urlapp:other' %}">go to other page </a>
    <br/>
    <a href="{% url 'admin:index' %}"> admin page</a>
    
    **error inccorect code some white space still get same error ** 
    
    <a href="{% url 'urlapp:other' %}">go to other page </a>
    <br/>
    <a href="{% url 'urlapp: other' %}">go to other page </a>
    <br/>
    <a href="{% url 'admin:index' %}"> admin page</a>
    <br/>
    <a href="{% url 'admin':index %}"> admin page</a>
    

    【讨论】:

      【解决方案3】:

      当我忘记静态文件路径周围的 '' 时出现此错误

      这给出了错误:

       <link rel='stylesheet' href="{% static css/style.css %}">
      

      这修复了错误:

       <link rel='stylesheet' href="{% static 'css/style.css' %}">
      

      【讨论】:

        【解决方案4】:

        {% %} 标记内,变量不被{{ 包围。试试这个:

        {% ifequal num buildSummary_list.number %}
        

        此外,您的两个比较似乎可以与 else 相结合:

        {% for num in buildSummary_list.paginator.page_range %}
            {% ifequal num buildSummary_list.number %}
                <b>{{num}}</b>
            {% else %}
                <a href="?page={{num}}"><b>{{num}}</b></a>
            {% endifequal %}
        {% endfor %}
        

        【讨论】:

        • 如果你在应该使用 {% %} 的地方使用 {{ }} 也会发生这种情况
        猜你喜欢
        • 2011-11-06
        • 2013-10-26
        • 2018-03-31
        • 2020-05-10
        • 2017-11-18
        • 1970-01-01
        • 2022-10-05
        • 2019-03-12
        • 2011-07-11
        相关资源
        最近更新 更多