tailieunhanh - Web to py enterprise web framework - p 14

HTTP AND REDIRECT 115 HTTP and redirect web2py defines only one new exception called HTTP. This exception can be raised anywhere in a model, a controller, or a view with the command: 1 raise HTTP(400, "my message") It causes the control flow to jump away from the user’s code, back to web2py, and return an HTTP response like: 1 2 3 4 5 6 7 8 9 HTTP/ 400 BAD REQUEST Date: Sat, 05 Jul 2008 19:36:22 GMT Server: CherryPy/ WSGI Server Content-Type: text/html Via: Connection: close Transfer-Encoding: chunked my message The first argument of HTTP is the HTTP status code. The second argument is the string. | HTTP AND REDIRECT 115 1 1 2 3 4 5 6 7 8 9 1 1 2 3 4 5 6 7 8 9 10 1 HTTP and redirect web2py defines only one new exception called http. This exception can be raised anywhere in a model a controller or a view with the command raise HTTP 400 my message It causes the control flow to jump away from the user s code back to web2py and return an HTTP response like HTTP 400 BAD REQUEST Date Sat 05 Jul 2008 19 36 22 GMT Server CherryPy WSGI Server Content-Type text html Via 8000 Connection close Transfer-Encoding chunked my message The first argument of http is the HTTP status code. The second argument is the string that will be returned as the body of the response. Additional optional named arguments are used to build the response HTTP header. For example raise HTTP 400 my message test hello generates HTTP 400 BAD REQUEST Date Sat 05 Jul 2008 19 36 22 GMT Server CherryPy WSGI Server Content-Type text html Via 8000 Connection close Transfer-Encoding chunked test hello my message If you do not want to commit the open database transaction rollback before raising the exception. Any exception other than http causes web2py to roll back any open database transaction log the error traceback issue a ticket to the visitor and return a standard error page. This means that only http can be used for cross-page control flow. Other exceptions must be caught by the application otherwise they are ticketed by web2py. The command redirect http is simply a shortcut for 116 THE CORE 1 raise HTTP 303 2 You are being redirected a href s here a location 3 Location http The named arguments of the http initializer method are translated into HTTP header directives in this case the redirection target location. redirect takes an optional second argument which is the HTTP status code for the redirection 303 by default . Change this number to 307 for a temporary redirect or to 301 for a permanent redirect.

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
6    139    0    29-06-2024
13    124    0    29-06-2024
309    110    0    29-06-2024