Answer the question
In order to leave comments, you need to log in
How to set django loop limit in tags?
There is a mini-feed with news, you need to limit the number of news to 5
Answer the question
In order to leave comments, you need to log in
If you need a paginator:
from django.views.generic import ListView
class NewsList(ListView):
model = News
paginate_by = 5
class News(Model):
# Твоя модель новостей
@classmethod
def last_five(cls):
return cls.objects.all()[:5]
<div class="my-very-own-news">
{% for news in News.last_five %}
{{ news }}
{% endfor %}
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question