Measuring open the road to one hundred twenty-eight: flask of 404 redirects and

 

 

a, b two views, respectively, of the page to return a page and b

 

 

 

 

Redirect: redirect

Route redirection to: request / a /, the redirected to / b /

 

 

 

Redirect to view function: url_for ( "function"), access to / a /, the redirect to function B ()

 

 

 

Voluntary Return 404: abort

 

 

 

Coding #: UTF-. 8 
from the Flask Flask Import, the render_template, the redirect, the url_for, ABORT

App = the Flask (__ name__)


active return visit # 404 / help / time
@ app.route ( '/ help /')
DEF req_help ():
ABORT (404)


@ app.route ( "/ A /")
DEF A ():
# return the render_template ( "a.html")
# return the redirect ( '/ B /')
return the redirect (the url_for ( 'B')) # The view routing address binding function name


@ app.route ( "/ B /")
DEF B ():
return the render_template ( "b.html")


IF the __name__ == '__main__':
app.run (Debug = True)

 

Guess you like

Origin www.cnblogs.com/zhongyehai/p/11442999.html