Django Template Language

Hello,

In the the html file I need to iterate though a list of objects passed from views.py to the hmtl by render ( Product_list = Product.objects.all() ) from the object 3 to 8, how this can be done?
{% for i in Product_list %} {% endfor %}

thanks.

What if you do this slicing before the template gets the values?
I mean, do you really need this job to be done only by the template?

You can do:
Product.objects.all()[3:8] and pass that to your context

1 Like

Hello,

Thanks for the reply.
Before this post I did try it But it did not work. I tried again and this time it worked.
I wonder if there is a way to do it in the html by a custom template tags and filters?

Thanks.

Example from link
{{ company|slice:‘4:7’ }}

2 Likes

Yes that is what I was looking for.
Thanks a lot.

1 Like