When from a page , I goto another page via some hyperlink,is there any way to go back to the previous page. The previous page has some arguments also. SO I want to ask whether the previous page is saved somewhere or is there any other way to go back to th开发者_StackOverflowat page
In http there is a header field called "referrer". If present it point to the previous page. You can access it from web2py:
if request.env.http_referer:
redirect(request.env.http_referer)
You have to be careful doing this if using a form on the page, since the initial load of the page will have the correct referer, however after submitting the form, the referer will be the page itself. To work around, I did something like this:
if session.back:
redirect_url = session.back
else:
redirect_url = URL()
# create form, do stuff, etc.
if form.accepts(request.vars.session):
session.back = None
else:
session.back = request.env.http_referer
精彩评论