views
def cat_detail(request, category_id):
category = Category.objects.get(id=category_id)
products = Product.objects.filter(category=category)
paginator = Paginator(products, 3)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
return render(request, 'product/cat_detail.html',
{'category': category, 'products': products, 'page_obj': page_obj})
html
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">« first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last »</a>
{% endif %}
</span>
</div>
paginator = Paginator(products, 3) Эта строка во views не работаtn, отображаются все продукты, а не 3