Python's Web Framework Django

Source: Internet
Author: User

  Python's Web Framework:

Django

I. The nature of the Web Framework:

For all web applications, essentially a socket server, the User's browser is actually a socket client.

1 #!/usr/bin/env python2 #Coding:utf-83 4 #the infrastructure of the web framework, which almost all developers are extending based on this underlying result. 5 6 ImportSocket7   8 defhandle_request (client):9BUF = Client.recv (1024)TenClient.send ("http/1.1 ok\r\n\r\n") oneClient.send ("Hello, Seven.") a    - defMain (): -Sock =Socket.socket (socket.af_inet, Socket. Sock_stream) theSock.bind (('localhost', 8000)) -Sock.listen (5) -    -      whileTrue: +connection, address =sock.accept () - handle_request (connection) + connection.close () a    at if __name__=='__main__': -Main ()

TWO. implementation of the Web Framework:

1. Based on the WSGI specification:

WSGI (Web Server Gateway Interface) is a specification that aims to provide a common API standard between the Web server and the Web framework layer, reducing interoperability and creating a unified invocation Approach. It solves many existing frameworks, such as django, Flask, web.py, and so on, and the Django application is quite Extensive.

A simple reference server (wsgirefs) is available in the Python standard library: wsgiref.simple_server. Wsgiserver.

1 #!/usr/bin/env python2 #Coding:utf-83  4  fromWsgiref.simple_serverImportMake_server5  6 defrunserver (environ, start_response):7Start_response ('OK', [('Content-type','text/html')])8     return ''9  Ten if __name__=='__main__': onehttpd = Make_server ("', 8000, Runserver) a     Print "serving HTTP on port 8000 ..." -Httpd.serve_forever ()

2. Custom socket, representative of TORNADO.

Three. Customize a Web Framework:

Python's Web Framework Django

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.