python - 无法解析余数 : '%' from '%' Django

标签 python django jinja2

我正在使用 Django Mezannine,我遇到了一个关于 jinja 的奇怪问题。

TemplateSyntaxError at /services/
Could not parse the remainder: '%' from '%'
Request Method: GET
Request URL:    http://192.168.1.14/services/
Django Version: 1.8.3
Exception Type: TemplateSyntaxError
Exception Value:    
Could not parse the remainder: '%' from '%'
Exception Location: /usr/local/lib/python3.4/dist-packages/django/template/base.py in __init__, line 639
Python Executable:  /usr/bin/python3
Python Version: 3.4.3

我的代码如下所示:

{% for image in images %}
   {% if loop.index % 3 == 0 %} #this is the line it doesn't like
     {{image}}
    {% endif %}
{% endfor %}

知道这里发生了什么吗?

谢谢

最佳答案

% 由 Django 保留,所以你必须使用 divisibleby

{% for image in images %}
    {% if forloop.counter|divisibleby:"3" %}
       {{image}}
    {% endif %}
{% endfor %}

关于python - 无法解析余数 : '%' from '%' Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32917933/

相关文章:

javascript - 点击每个链接时django加载模式

python - 应用于滚动数据帧太慢(pandas 0.23.4)

python - 如何在 Python 中分析内存使用情况?

python - 如何从 Python 字典中的键中删除尾随空格?

Django View 有一个意外的关键字参数

css - 如何将 css 添加到 flask 应用程序中的 remember_me?

python ghostscript 不关闭输出文件

python - 在 Django 中显示来自数据库的动态数据

python - 请求之间 Django 中对象的对象存储

google-cloud-platform - Ansible 中的复杂数据结构