rajivraj
asked on
How to loop a certain number of times in Django?
I want loop a certain number of times.. say 5 or 10. I see a lot of code the loop through a collection.
You can use the slice filter in a template like so:
{% for r in web.results|slice:"0:5" %}
{{ r.title }}
{% endfor %}
{% for r in web.results|slice:"0:5" %}
{{ r.title }}
{% endfor %}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
code here repeats 5 times
If that is not what you are looking for then please explain.
How does this relate to django? To a collection?