This error is a bug that comes up when there is no data added to the events table, therefore no data to be paginated. To resolve this issue simply cache the all_appointment and today_appointment views with a try-except as seen below to handle cases when there is no data.
deftoday_appointment(request):if"user"inrequest.session:try:appointments=client.query(q.paginate(q.match(q.index("events_today_paginate"),request.session["user"]["username"],str(datetime.date.today()))))["data"]appointments_count=len(appointments)page_number=int(request.GET.get('page',1))appointment=client.query(q.get(q.ref(q.collection("Events"),appointments[page_number-1].id())))["data"]ifrequest.GET.get("complete"):client.query(q.update(q.ref(q.collection("Events"),appointments[page_number-1].id()),{"data":{"status":"True"}}))["data"]returnredirect("App:today-appointment")ifrequest.GET.get("delete"):client.query(q.delete(q.ref(q.collection("Events"),appointments[page_number-1].id())))returnredirect("App:today-appointment")context={"count":appointments_count,"appointment":appointment,"page_num":page_number,"next_page":min(appointments_count,page_number+1),"prev_page":max(1,page_number-1)}returnrender(request,"today-appointment.html",context)except:returnrender(request,"today-appointment.html")else:returnHttpResponseNotFound("Page not found")defall_appointment(request):if"user"inrequest.session:try:appointments=client.query(q.paginate(q.match(q.index("events_index_paginate"),request.session["user"]["username"])))["data"]appointments_count=len(appointments)page_number=int(request.GET.get('page',1))appointment=client.query(q.get(q.ref(q.collection("Events"),appointments[page_number-1].id())))["data"]ifrequest.GET.get("delete"):client.query(q.delete(q.ref(q.collection("Events"),appointments[page_number-1].id())))returnredirect("App:all-appointment")context={"count":appointments_count,"appointment":appointment,"next_page":min(appointments_count,page_number+1),"prev_page":max(1,page_number-1)}returnrender(request,"all-appointment.html",context)except:returnrender(request,"all-appointment.html")else:returnHttpResponseNotFound("Page not found")
This error is a bug that comes up when there is no data added to the events table, therefore no data to be paginated. To resolve this issue simply cache the
all_appointment
andtoday_appointment
views with a try-except as seen below to handle cases when there is no data.Hope this helps, thank you.
Okay, Cool.
I will try this out.