-6👍
Use your view function to prepare your list before passing it to the template.
Django template isn’t intended for complex matching like this.
Exactly as discussed 😉
27👍
You could have used slice
if there isn’t {% if category.reward_type == reward_type %}
.
i.e. if you have category_matching_rewards
which is list having category.reward_type == reward_type
then in template it can be done as
{%for category in category_matching_rewards|slice:"4" %}
Show catgory
....
{%endfor%}
- [Django]-Django aggregate average of an annotation sum (1.6.5)
- [Django]-Access denied issue when I try to access a shared drive from Django running in Apache
4👍
You may use forloop.counter
, The for
loop sets a number of variables available within the loop:
forloop.counter
The current iteration of the loop (1-indexed)
forloop.counter0
The current iteration of the loop (0-indexed)
forloop.revcounter
The number of iterations from the end of the loop (1-indexed)
forloop.revcounter0
The number of iterations from the end of the loop (0-indexed)
forloop.first
True if this is the first time through the loop
forloop.last
True if this is the last time through the loop
forloop.parentloop
For nested loops, this is the loop above the current one
- [Django]-Model inheritance in django-nonrel on app engine
- [Django]-How to use date__range filter efficiently in django
- [Django]-Django-mptt filter without breaking the tree