Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:29:20+00:00 2026-06-03T20:29:20+00:00

I read here that Django querysets are lazy, it won’t be evaluated until it

  • 0

I read here that Django querysets are lazy, it won’t be evaluated until it is actually printed. I have made a simple pagination using the django’s built-in pagination. I didn’t realize there were apps already such as “django-pagination”, and “django-endless” which does that job for.

Anyway I wonder whether the QuerySet is still lazy when I for example do this

entries = Entry.objects.filter(...)
paginator = Paginator(entries, 10)
output = paginator.page(page)
return HttpResponse(output)

And this part is called every time I want to get whatever page I currently I want to view.

I need to know since I don’t want unnecessary load to the database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:29:21+00:00Added an answer on June 3, 2026 at 8:29 pm

    If you want to see where are occurring, import django.db.connection and inspect queries

    >>> from django.db import connection
    >>> from django.core.paginator import Paginator
    >>> queryset = Entry.objects.all()
    

    Lets create the paginator, and see if any queries occur:

    >>> paginator = Paginator(queryset, 10)
    >>> print connection.queries 
    []
    

    None yet.

    >>> page = paginator.page(4)
    >>> page
    <Page 4 of 788>
    >>> print connection.queries 
    [{'time': '0.014', 'sql': 'SELECT COUNT(*) FROM `entry`'}]
    

    Creating the page has produced one query, to count how many entries are in the queryset. The entries have not been fetched yet.

    Assign the page’s objects to the variable ‘objects’:

    >>> objects = page.object_list
    >>> print connection.queries
    [{'time': '0.014', 'sql': 'SELECT COUNT(*) FROM `entry`'}]
    

    This still hasn’t caused the entries to be fetched.

    Generate the HttpResponse from the object list

    >>> response = HttpResponse(page.object_list)
    >>> print connection.queries
    [{'time': '0.014', 'sql': 'SELECT COUNT(*) FROM `entry`'}, {'time': '0.011', 'sql': 'SELECT `entry`.`id`, <snip> FROM `entry` LIMIT 10 OFFSET 30'}]
    

    Finally, the entries have been fetched.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read so many times, here and everywhere on the net, that mutexes
I have read in a several places (e.g. here ) that I can use
I have read other questions on this topic but none that actually answers my
I've read a few answers on here that condemn the use of svn:externals. I
I read here about std::auto_ptr<>::operator= Notice however that the left-hand side object is not
When I read some of the answers on here I notice that some people
Here is the thread that I read about making a stack of resources from
I read the MSDN documentation and examples here and I know that the correct
I have read here http://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/ about how you probably shouldn't be trying to un-flatten
I've read the Django documentation here: http://docs.djangoproject.com/en/dev/ref/forms/validation/ I've also browsed a number of search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.