The Python Oracle

Django Lazy Loading Pagination

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC G Dvoks String Quartet No 12 Ame 2

--

Chapters
00:00 Question
02:14 Accepted answer (Score 1)
02:59 Thank you

--

Full question
https://stackoverflow.com/questions/3570...

Question links:
[Django Endless Pagination]: http://django-endless-pagination.readthe.../

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#jquery #python #django #pagination #djangoendlesspagination

#avk47



ACCEPTED ANSWER

Score 1


Django Ajax would allow you to make Ajax calls to a Django view. You could wrap your results in a list then cache that. From there just pop the first 50 (or whatever size you want to set) when you initially render the view. Then pop your cache on the Ajax call.

Something like:

@django_ajax
def paginated_cache(request):
    more_results = [cache.get('your_results').pop() for result in range(50)]
    # turn this to json, wrap in dictionary and return

A more detailed instruction is on the django ajax page. This is for a smaller result size. For bigger results you may want to use something like a cursor though.