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

  • Home
  • SEARCH
  • 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 8279315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:17:44+00:00 2026-06-08T09:17:44+00:00

I’m working on a web application in web2py. I want to introduce pagination to

  • 0

I’m working on a web application in web2py. I want to introduce pagination to it but I have no database in my application. It isn’t needed. I will have a list of up to 100 items but could be as little as 50. I want to generate the number of pages needed and want to show 10 per page. Can anyone point me in the right direction? Can’t make any sense of the web2py tutorial on it.

  • 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-08T09:17:45+00:00Added an answer on June 8, 2026 at 9:17 am

    T = total items
    I = items-per-page
    P = page

    Let T=100, I=10, page=0 (initial page)

    Pythonic Psuedocode:

    num_pages = Math.Ceil( T / I ) # ceil(100/10) = 10 pages
    cur_page = P # 0
    
    start = I*P # 10 * 0 = 0
    end = start + ipp # 0 + 10 = 10
    if end > total: # false
      end = total
    
    items = allitems[start:end] # this page's items
    

    This should get you started. Test, debug and tweak as needed.

    Let T=322, I=50, page=6

    num_pages = Math.Ceil( T / I ) # ceil(322/50) = 7 pages
    cur_page = P # 6
    
    start = I*P # 50 * 6 = 300
    end = start + ipp # 300 + 50 = 350
    if end > total: # true 
      end = total # end = 322, not 350
    
    items = allitems[start:end] # this page's items
    

    So, this logic all goes in the controller, where Items_Per_page is hardcoded on the server or received as a GET/POST variable when you click on a link or submit button. You’ll need to do the latter if you want the user to be able to select different amounts of items per page. Page is definitely received from the request as a GET/POST var (I would recommend GET as it’s easier in this case). T, total number of items, is easy — just say “len(data)” where data is an iterable.

    Controller:

    def show_items():
        T = len(data) # not sure where your data comes from, or if you have to process a query first...
        P = request.vars.page # e.g. http://blah.com/show_items?page=0
        I = request.vars.ipp # e.g. http://blah.com/show_items?page=0&ipp=50
    
        #now the code from before...
        num_pages = Math.Ceil( T / I ) # ceil(100/10) = 10 pages
        cur_page = P # 0
    
        start = I*P # 10 * 0 = 0
        end = start + ipp # 0 + 10 = 10
        if end > total: # false
          end = total
    
        items = allitems[start:end] # this page's items
    
        return dict(
          data=items,
          start=start,
          end=end,
          total=total,
          prev=page-1 if page > 0 else None, # set to None if page =0
          next=page+1 if page < num_pages else None, # set to None if page == num_pages
        )
    

    So that’s the controller. Now the view has access to data, start, end and total, and also prev and next.

    I just realized the post is titled and tagged with web2py … so ignore any statements about your intended framework, here’s a web2py solution (untested, probably needs tweaks). Also, I use the x = value_if_true if expression else value_if_false which is not available before python 2.6 I think, so you might have to refactor.

    {{ extend 'layout.html' }}
    
    {{ if not total > 0: }}
      No results
    {{ else: }}
      <div id='items-container'>
        <div id='items-nav'>
          <span class='header'>Showing {{=start}} to {{=end} of {{=total}}</span><br />
          {{ if prev != None: }}
          <a href='show_items?ipp={{=ipp}}&page={{=prev}}' class='prev p-nav' style='float: left'>&lt; Prev</a>
          {{ pass }}
    
          {{ if next != None: }}
          <a href='show_items?ipp={{=ipp}}&page={{=next}}' class='next p-nav' style='float: right'>Next &gt;</a>
          {{ pass }}
        </div>
    
        {{ for item in items: }}
        <div class='item'>
          {{=item.title}}<br />
          {{=item.description}}<br />
          Put whatever else about the item...
        </div>
        {{ pass }}
    
      </div>
    {{ pass }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.