Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not parse the remainder: '%' from '%' Django

I am working with Django Mezannine and I am running into a weird issue with 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

My code looks something like below:

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

Any idea what is going on here?

Thanks

like image 992
nick_v1 Avatar asked Oct 15 '25 14:10

nick_v1


1 Answers

% is reserved by Django so you have to use divisibleby

{% for image in images %}
    {% if forloop.counter|divisibleby:"3" %}
       {{image}}
    {% endif %}
{% endfor %}
like image 51
snorp Avatar answered Oct 18 '25 05:10

snorp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!