The understanding of citrus

Source: Internet
Author: User

The logic of the code when the request occurs is as follows: 1, Http://localhost:8081/foo/dbins?name=hello first step: Run citrus.py's route function when the above request occurs, according to the Flask Route code: @ App.route ('/<controller>/<action> ',  methods = [' get ',  ' post '), the route is registered with the GET and POST methods , the address has two dynamic parameter controller and action, according to the View function route (Controller, Action), at this time the controller is foo,action is Dbins, The request is distributed to the Controller.foo Doins method, and this function is returned (called). Step two: Run the Dbins method: (1) Call the Parse_request function in the _ctl_ module, where the keyword parameter get is the list [' name ']; (2) because at this time the Parse_request function   post defaults to None , the Parse_request function returns the value "Hello" for the "name" in the link in the form of a tuple, and (3) invokes the Foo function in the model file with the result "Hello" in the previous step, and the Foo function primarily creates the class (with the ID and name attribute). and assigns the passed "hello" parameter to the object's Name property, (4) calls the Citrus DB object, adds and submits the object instantiated in the previous step to the database, and returns "new Foo ID: (The object's ID value)."  2, Parse_request Method Understanding: (1) The method contains get, post parameters, the default value is None; (2) Define a try to handle the exception, (3) Define an empty list ret ; (4) The requested form content is assigned to form in combinedmultidict form, the parameter combinedmultidict of the request link is assigned to args, and (5) If the post is true (that is, non-null or not 0), Add all values of the form (form values) to the RET list, (6) If Get is true (that is, non-null or not 0), all values of the parameters in the link are added to the RET list, (7) The RET is returned as a tuple, and (8) If there is an exception, raise/ Throws a custom exception Citrusexception,errcode to the Invalid_request_ar of the module _err_GS, Value 1001.   3, POST http://localhost:8081/foo/postget?args1=a1&args2=a2Content-type:application/ X-WWW-FORM-URLENCODEDPOST_BODY:FORM1=F1&AMP;FORM2=F2 (1) The link is basically similar to the 1th, the request is distributed to the Controller.foo Postget method, and the function is returned (called). (2) Call the Parse_request method  , where post = [' Form1 ', ' Form2 '],get=[' args1 ', ' args2 '], get ' Form1 ', ' Form2 ', ' args1 ', ' ARGS2 ' The corresponding value, returned and assigned to Form1, Form2, ARGS1, ARGS2; If the argument is insufficient or superfluous, an exception is thrown: Std err:1001. (3) Return to Form1, Form2, ARGS1, Args2.   Second, Cookie and session understanding: 1, the cookie is mainly used for user identification and state management, when the customer service side of the user ID and password and other relevant information sent to the server, the server returned to the client is not only the requested information, there is a session ID included , date and time of the cookie, and save it on the user's hard drive, whose life cycle is the expiration time of the cookie upload or end of the browser session (if no expiration time is specified). Session is mainly to put the user's request information on the server side to save, the server will return the session ID, but also the user's authentication status and session ID bound on the server side. 2. When the client accesses the server again, the cookie is automatically sent with the session ID, and the server can identify the user and its authentication status by verifying the received session ID, so that the client is not required to enter the user information each time. 3, because the cookie can be artificially prohibited, you can use the session ID directly appended to the URL path after the URL rewriting technology to send the session ID to the server.

Understanding of the citrus

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.