191👍
✅
There is a slice
filter that you can use in templates. This works exactly the same as slicing within the view.
{% for new in news|slice:":10" %}
13👍
You want to use the slice template filter
Here’s your example altered to use it:
<ul>
{% for new in news|slice:":3" %}
<li>
<p>{{ new.title }}</p>
<p>{{ new.body }}</p>
</li>
{% endfor %}
</ul>
- [Django]-Is there a way to filter a queryset in the django admin?
- [Django]-Data Mining in a Django/Postgres application
- [Django]-How do I use pagination with Django class based generic ListViews?
Source:stackexchange.com