in the development of the Web site, there will be a number of page jump function requirements, such as login to jump to the user's personal page, such as log in and jump to the login page.
in web.py , This function can be achieved using Web.seeother or Web.redriect. Like
Import Weburls = ('/hello ', ' Index ', '/welcome ', ' welcome ') app = Web.application (URLs, Globals ()) render = WEB.TEMPLATE.R Ender (' templates/') class Welcome (object):d EF get (self): return Render.welcome (), Class Index (object):d EF get (self): Return Render.hello_form () def POST (self): Raise Web.seeother ('/welcome ') #raise web.redirect ('/welcome ') if __name__ = = "__main__": App.run ()
web.py page jumps are implemented in two ways:web.seeother and web.redirect. In general , it is recommended to use Web.seeotherinstead of Web.redirect, what is the difference between these two ways?
The status code returned by Web.seeother is 303 See other:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/7E/wKiom1TUU1fDlggbAACrv921OfU882.jpg "style=" float: none; "title=" 1.png "alt=" Wkiom1tuu1fdlggbaacrv921ofu882.jpg "/>
The status code returned by Web.redirect is 301 Moved Permanently
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/7A/wKioL1TUVEXgZWbxAACZIvED3Xg517.jpg "title=" 2.png " Style= "Float:none;" alt= "wkiol1tuvexgzwbxaaczived3xg517.jpg"/>
so What's the difference between 303 seeother and 301 movedpermanently ?
Both of These status codes tell the client: the resource you requested is moved elsewhere, I give you the address of the resource, you go to that place to find it. The difference is:301 is permanently moving,303 is temporarily moving.
because we are using a browser, and do not realize this process. If you do web crawler development, these status code is very important. For a Web page where the status code returns 301, when the address mapping is recorded, the new location can be recorded directly , thus avoiding an unnecessary request and increasing the efficiency of the request.
for server-side development, you should use Web.seeother more , because browsers cache Web pages. If you use web.redirect, the browser ignores the cache and accesses the website directly. It is not good for the user experience.
of course, there is a scenario that is suitable for Web.redirect, where users typically bookmark pages in their browsers. In order to make the user's collection not expire, it is necessary to use web.redirect.
This article is from a "little progress every Day" blog, make sure to keep this source http://sbp810050504.blog.51cto.com/2799422/1612326
web.py Framework Web.seeother VS Web.redirect