The problem is that form should be before select. Anyway you do not
need to actions.
I suggest the following changes:
def index():
items_page=20
page_no=int(request.args(0) or 0)
limitby=(items_page*page_no,items_page*page_no+items_page+1)
#notice + 1
form=crud.create(db.whoelse,next=URL(r=request),message='Your
message is posted')
messages=db(db.whoelse.id>0).select(orderby=~db.whoelse.created_on,limitby=limitby)
prev = (page>0) and URL(r=request,args=page_no-1)
next = (len(messages)==items_page+1) and URL(r=request,args=page_no
+1)
return dict(messages=messages[:items_page], entries=entries,
form=form,page=page_no,prev=prev,next=next)
and corresponding view part:
------------------------------------------
{{=form}}
{{=messages}}
{{if prev:}}<a href="{{=prev}}">previous</a>{{pass}}
{{if next:}}<a href="{{=next}}">previous</a>{{next}}
------------------------------------------
On May 26, 3:12 am, NoNoNo <[email protected]> wrote:
> Hi,
>
> I'm quite new to web2py and currently building a simple application: a
> message board, listing latest 20 messages by index(). For earlier
> messages, there is a self-submitting form to enter page number (20
> message each page) to go to, and after submitting the form, redirects
> to that page. Here is the question on the self-submitting form:
> nothing changed (always showing the 1st page) whatever number is input
> into the form. Controller as follows:
>
> def index():
> page_no=1
> entries=db(db.whoelse.id > 0).count()
> messages=db((db.whoelse.id>(entries-20)) &
> (db.whoelse.id<=entries)).select(db.whoelse.ALL,
> orderby=~db.whoelse.created_on)
>
> if request.vars.page_no:
> if request.vars.page_no>(entries/20+1):
> redirect(URL(r=request, f='index'))
> else:
> redirect(URL(r=request, f='gotopage')
> form=crud.create(db.whoelse,
> next=URL(r=request,args=1),message='Your message is posted')
> return dict(messages=messages, entries=entries,
> form=form,page=page_no)
>
> def gotopage():
> entries=db(db.whoelse.id > 0).count()
> messages=db((db.whoelse.id>(entries-request.vars.page_no*20)) &
> (db.whoelse.id<=((entries-
> (request.vars.page_no-1)*20)))).select(db.whoelse.ALL,
> orderby=~db.whoelse.created_on)
>
> form=crud.create(db.whoelse,
> next=URL(r=request,args=1),message='Your message is posted')
> return dict(messages=messages, entries=entries, form=form,
> page=request.vars.page_no)
> ------------------------------------------
> and corresponding view part:
> <h5>{{=page}}/{{=entries/20+1}} Pages Go to
> page:<form><input name="page_no" /> <input type="submit" /></form></
> h5>
> ------------------------------------------
>
> Any reply will be appreciated.
>
> Spring