Python class library 26 [url ing for web2py]

Source: Internet
Author: User
Tags vars web2py

 

URL ing of web2py

1) ing of http: // 127.0.0.1: 8000/A/C/f.html

The URL ing rule of web2py maps http: // 127.0.0.1: 8000/A/C/f.html to the function (F) of controller (C) of application (). If function (f) does not exist, it is mapped to the function (INDEX) function of controller (c. If controller (c) does not exist, web2py maps to Controller (default) by default. If application (a) does not exist, web2py maps to application (init) by default. If application (init) if it does not exist, web2py maps to application (welcome ).

 

 

By default, any new request will create a new session, and session cookie will return the session information to the user's browser.

Web2py automatically and transparently records visitors using sessions and cookies. For each new visitor, it creates a session and assigns a unique session_id. Session is a variable container stored on the server. Session IDs are sent back to the visitor's browser through cookies. When a visitor requests another page in the same application, the browser returns the cookie. on the server side, web2py checks the cookie and stores the corresponding session.

 

 

. Html extension is the default page extension, which determines the view used to render the Controller's function. This method allows the page to be rendered in multiple formats (HTML, XML, JSON, RSS, etc ).

 

2) ing of http: // 127.0.0.1: 8000/A/static/filename

A special case of URL ing: http: // 127.0.0.1: 8000/A/static/filename maps this request to subfolder (static) under application () file (filename ). When a static file is downloaded, web2py does not create a session or return a cookie or run models. Web2py always streams static files into 1 MB blocks. When the client sends a range request to the file, partial content will be returned.

 

Web2py also supports the if_modified_since protocol. If the file has been cached in the browser and has not been changed since the previous version, the file will not be returned.

 

3) http: // 127.0.0.1: 8000/A/C/f.html/x/y/z? Ing of p = 1 & Q = 2
Web2py converts http: // 127.0.0.1: 8000/A/C/f.html/x/y/z? P = 1 & Q = 2 maps to the function (F) of controller (c) of application (A), and stores parameters in the URL to the request variable, as follows:
Request. ARGs = ['x', 'y', 'z']
Request. vars = {'P': 1, 'q': 2}
Request. Application = 'A'
Request. Controller = 'C'
Request. Function = 'F'

In the preceding example, request. ARGs [I] and request. ARGs (I) are used to obtain the I element of request. args.

 

Request. url stores the full URL of the current request (excluding the get variable ).

 

If the HTTP request is get, request. Env. request_method is set to get. If the request is post, request. Env. request_method is set to post.

The URL query variables are stored in the request. vars storage dictionary. If the request is GET request, the variables are stored in request. get_vars at the same time. If the request is post, the variables are stored in request. post_vars.

Web2py stores wsgi and web2py environment variables in request. for example, request. env. path_info = 'A/C/F', stores the HTTP header in the environment variable, such as request. env. http_host = '2017. 0.0.1: 8000 '.

 

4) Summary

Web2py requests to static files, but simply reads and returns the stream of the requested files.

 

For non-static files, the process is as follows:
1) Parse cookies;
2) create an environment to execute functions;
3) initialize request, response, cache;
4) open an existing session or create a new session;
(5) execute the models of the request application;
6) execute the Action Function of the Request controller;
7) if the function returns dictionary, the corresponding view is executed;
(8) If successful, submit all opened transactions;
9) maintain the session;
10) returns an HTTP response;

 

Note: The Controller and view are executed in different copies in the same environment. The controller is invisible to the view, but the view can access models and the variables returned by the Controller action function.

 

If an exception (not an HTTP exception) occurs, web2py performs the following actions:
1) store the traceback of the error file and assign a ticket number;
2) Roll back all opened transactions;
3) An error page containing the ticket number is returned;

If an HTTP exception occurs, it is considered an internal action, and all opened database transactions are committed.

 

Complete!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.