Python Simple Web Server example

Source: Internet
Author: User

Reference: Http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/ 001386832689740b04430a98f614b6da89da2157ea3efe2000

Code:

hello.py

1 #!/usr/bin/python2 #Coding:utf-83 4 #hello.py5 defapplication (environ, start_response):6Start_response ('OK', [('Content-type','text/html')])7     return ''% (environ['Path_info'][1:]or 'Web')

server.py

1 #!/usr/bin/python2 #Coding:utf-83 4 #server.py5  fromWsgiref.simple_serverImportMake_server6  fromHelloImportApplication7 8 #Create server, IP is empty, port was 8000, handle function is application9httpd = Make_server ("', 8000, application)Ten Print "serving HTTP on port 8000 ..." One #Start Listen HTTP request AHttpd.serve_forever ()

The module wsgiref is used. It implements the Wsgi interface, we only need to set a WSGI processing function to handle the resulting request.

Using Python to implement these seemingly complex instance programs is very simple, thanks to Python's powerful libraries.

Python Simple Web Server example

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.