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.
rajivrajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ramromconsultant Commented:
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?
0
IrishPheremoneCommented:
You can use the slice filter in a template like so:

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



0
bram_19277Commented:
i = 1
setloop = 5

for i <= 5:
    <do the loop here>
    i = i + 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.