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 &&MTVMVC 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