Link to home
Start Free TrialLog in
Avatar of rajivraj
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.
Avatar of ramrom
ramrom
Flag of United States of America image

for i in range(5):
  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?
Avatar of IrishPheremone
IrishPheremone

You can use the slice filter in a template like so:

{% for r in web.results|slice:"0:5" %}
  {{ r.title }}
{% endfor %}



ASKER CERTIFIED SOLUTION
Avatar of bram_19277
bram_19277

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial