1

Currently, I am implementing an Django view which reads from a MySQL database, saves that table into a Pandas dataframe, converts that table into a JSON string, then loads that string into a list.

Code:

def myView(request):
   ...
   #saved dataframe = df
   JSON = df.to_json(orient="records")
   JSON = json.loads(JSON)
   return django.http.JsonResponse(JSON, safe=False)

The issue is that with our database, after N number of objects being rendered on the browser, the browser crashes and says it is "out of memory". So, I'm trying to put implement pagination into its view. The problem is that the class 'django.core.paginator.Paginator' is not serializable.

There is not many solutions that I could find online. This is the only one I could find: Serializing a pagination object in Django, and my Django project doesn't use models so this one isn't useable. Therefore, does anyone have any advice?

I know I could use Django REST, but refactoring my project to use models has me worried I might corrupt our database so I'm trying to be safe.

lnogueir
  • 1,859
  • 2
  • 10
  • 21
  • 1
    The page object has the paged objects stored as `object_list`, so you can write `page.object_list` to access the results directly as a list (I assume your results are serializable). – Abdul Aziz Barkat Mar 06 '21 at 06:01
  • Thank you for clarifying this. Your recommendation - "page=pages.object_list[2]" works. And that unblocks me. Thanks again! However, I am still curious why "pages = Paginator(JSON)" does not work? – JustAnotherProgrammer Mar 09 '21 at 01:18

0 Answers0