Web Framework
All Web applications are essentially a socket server, and the user's browser is actually a socKet client.
Import socketdef handle_request (client): buf = Client.recv (1024x768) client.send ("http/1.1-ok\r\n\r\n". Encode ("UTF8")) client.send ("Hello, Word". Encode ("UTF8")) def Main (): sock = Socket.socket (socket.af_inet, Socket. SOCK_STREAM) sock.bind (("localhost", 9000)) Sock.listen (5) while True: connection, address = Sock.accept () handle_request (connection) Connection.close () if __name__ = = "__main__": Main ()
The above is achieved through the socket, but for the real development of the Python Web program, it is generally divided into two parts: server programs and Applications. The server program is responsible for encapsulating the socket server and collating the various data requested when the request arrives. The application is responsible for the specific logical processing. In order to facilitate the development of the application, there are many web frameworks, such as Django, Flask, web.py and so on. Different frameworks have different ways of developing them, but in any case, the applications you develop will have to work with the server program to provide services to the user. In this way, the server program needs to provide different support for different frameworks. This chaotic situation is bad for both the server and the framework. For the server, you need to support a variety of frameworks, for the framework, only the servers that support it can be used by the development of the application. Standardization becomes particularly important at this time. We can set up a standard that is supported by the framework as long as the server program supports this standard, so they can work with it. Once the criteria are determined, both parties are implemented. In this way, the server can support more frameworks that support standards, and the framework can use more servers that support standards
"Python"--web framework