Python Learning---framework basics of Python

Source: Internet
Author: User

Framework Basics

Framework Essence:

In essence, all Web applications are a socket server, and the user's browser is actually a socket client.

b/S structure response:

Import socketdef handle_request (client):    buf = Client.recv (1024x768)    client.send ("http/1.1-ok\r\n\r\n". Encode ("UTF8"))    client.send ("

Wsgi:web Server Gateway Interface

1. Encapsulating the socket object and the preparation process [socket creation, BIND, listen]

2. Through version, all the request objects are encapsulated, key-value pairs are encapsulated in the form of a dictionary, and key can be used to obtain the value

3. The response response head can be conveniently set by Start_response ()

Common sense:

Request is divided into request header and request body

If it is a GET request: The data is wrapped in a URL, no request body is required, only the request header

If it is a POST request: The data is wrapped inside the request body

Note: The request header and the request body are delimited by 2 line breaks

The From Wsgiref.simple_server import make_server//application () function must be called by the WSGI server because we cannot pass arguments to the function itself, and the arguments are internally encapsulated. def application (environ, start_response):    start_response (' OK ', [(' Content-type ', ' text/html ')]    return [ B ' 
MVC &&MTV

MVC is to divide Web applications into models (M), controllers (C), view (V) Three layers, and they are joined together in a plug-in, loosely coupled way.

The model is responsible for the business object with the database object (ORM), the view is responsible for interacting with the user (page), the controller (C) accepts the user's input call model and the view completes the user's request.

The Django MTV model is essentially no different from the MVC pattern, and it's just a little different from the definition of each component in order to remain loosely coupled, as Django's MTV represents:

Model: Object that is responsible for business objects and databases (ORM)

Template (Template): Responsible for how to display the page to the user (storing HTML files)

View: Responsible for business logic, and call model and template (similar to Conrtoller in MVC) when appropriate

In addition, Django has a URL dispatcher that distributes page requests for URLs to different view processes, and then calls the corresponding model and template

Python Learning---framework basics of Python

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.