title: How does django's pagination work in a django view
body: <p>So I was reading about pagination, I have done it quite a few times writing this app but I was wondering how does pagination in django work at sql level.</p>
  
  <pre><code>from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
  
  def listing(request):
      contact_list = Contacts.objects.all()
      paginator = Paginator(contact_list, 25) # Show 25 contacts 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_to_response('list.html', {"contacts": contacts})
  </code></pre>
  
  <p>Does <code>Contacts.objects.all()</code> get called evertime I am hitting the view ?
  Or does <code>Paginator</code> maintains a state somehow ? What would the sql query look like for <code>paginator = Paginator(contact_list, 25)</code> Are there generators being used behind the scenes and things are lazily evaluated?</p>
  
  <p>Sorry if this is a dumb question, there is a lot of abstraction in Django and I seem to miss all the action behind.
  Thanks in advance</p>