It is easy for Series
. I just pass it to paginator
. But, when I use DataFrame
, it is call "The truth value of a Series is ambiguous". Maybe, there are problem with count
method, but I don't know how I can change it. In my project DataFrame
must be split on pages by rows.
def listing(request):
contact_list = pd.DataFrame(np.arange(12).reshape(4,3))
paginator = Paginator(contact_list, 1) # Show 1 row per page
page = request.GET.get('page')
try:
contacts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
contacts = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
contacts = paginator.page(paginator.num_pages)
return render(request, 'list.html', {'contacts': contacts})