---------- Sent via Nokia Email
------Original message------ From: Russell Keith-Magee <russ...@keith-magee.com> To: <django-users@googlegroups.com> Date: Sunday, October 23, 2011 4:06:08 PM GMT+0800 Subject: Re: How to filter arithmetic seires in loop? On Sun, Oct 23, 2011 at 3:58 PM, Tsung-Hsien <jasoniem9...@gmail.com> wrote: > Thanks your advice! > However,using {% if forloop.counter % 4 == 1 %} shows problem that > Exception Value: > Could not parse the remainder: '%' from '%' > Now, I refer > http://stackoverflow.com/questions/1438486/how-to-use-math-remainder-in-django-template > and change it to {%forloop.counter|add:"-1"|divisibleby:4%}, and it > work! My apologies -- I had a momentary lapse of sanity. The modulus operator won't work in an if clause; the new divisibleby solution you've provided is correct. An alternate (and very slightly faster) way of saying it would be: {% if forloop.counter0|divisibleby: 4 %} This uses a counter that starts at 0, rather than one that starts at 1, removing the need to do the "add:-1" Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.