The Django paginator doesn't work if records (data) come via API, without querying the database
views.py
limit = request.GET.get('limit')
limit = int(limit) if limit else None
context['limit'] = limit
page = request.GET.get('page')
page = int(page) if page els
context['page'] = page
data_posting_orders = api.posting_orders(api_session, page=page, limit=limit) #
summary_count = api.get_summary(api_session).get('holder_summary')['count']
objects = data_posting_orders.get('transactions') # получение всех данных по api
paginator = Paginator(objects, 15)
try:
page_obj = paginator.get_page(page)
except PageNotAnInteger:
page_obj = paginator.get_page(1)
except EmptyPage:
page_obj = paginator.get_page(paginator.num_pages)
context['page_obj'] = page_obj
index.html
<div class="table-responsive">
<table id="posting-orders" class="order-column table-hover table-bordered nowrap"
bgcolor="#f0ffff" style="width:100%">
{% include 'includes/_header_table_posting_orders.html' %}
<tbody>
{% for order in page_obj %}
{% include 'includes/_body_table_posting_orders.html' %}
{% endfor %}
</tbody>
<tfoot>
<tr>
<th class="text-success font-weight-bold" colspan="5" style="text-align:right">Итого:
</th>
<th class="text-danger font-weight-bold" style="text-align: right"></th>
</tr>
</tfoot>
</table>
<nav hidden aria-label="...">
<ul style="" class="pagination justify-content-end">
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="?page=1">« Первая</a></li>
<li class="page-item"><a class="page-link"
href="?page={{ page_obj.previous_page_number }}">Пред</a>
</li>
{% endif %}
{% for page in page_obj.paginator.page_range %}
{% if page == page_obj.number %}
<li class="page-item active"><a class="page-link"
href="?page={{ page }}">{{ page }}</a>
</li>
{% elif page > page_obj.number|add:-3 and page < page_obj.number|add:3 %}
<li class="page-item"><a class="page-link"
href="?page={{ page }}">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link"
href="?page={{ page_obj.next_page_number }}">След</a></li>
<li class="page-item"><a class="page-link"
href="?page={{ page_obj.paginator.num_pages }}">Последняя({{ page_obj.paginator.num_pages }})</a>
</li>
{% endif %}
</ul>
The problem is that the paginator gets the whole list and then divides it into pages. And I think its work should be how to get records from API, not all at once but some of them.