class TestView(APIView):
def get(self, request):
page = int(request.GET.get("page", 1))
page_size = 10
limit = page_size * page
offset = limit - page_size
nubmer_of_data = len(data)
paged_data = data[offset:limit]
page_count = ceil(number_of_data / page_size)
if page_count < 1:
page_count = 1
context = {
"data": paged_data,
"page": page,
"page_count": page_count,
"page_range": range(1, page_count + 1),
}
return render(request, "test.html", context=context)
{% if page|slugify != "1" %}
<li class="pagination-prev">
<a href="?page={{ page|add:-1 }}">이전</a>
</li>
{% endif %}
{% for page in page_range %}
<li>
<a href="?page={{ page }}">{{ page }}</a>
</li>
{% endfor %}
{% if page|slugify != page_count|slugify %}
<li class="pagination-next">
<a href="?page={{ page|add:1 }}">다음</a>
</li>
{% endif %}