Python CGI programming and Cgihttpserver

Source: Internet
Author: User

Python2.7 's cgihttpserver can be used as a simple HTTP server, capable of invoking CGI scripts

1 Create a special directory cgi-bin in any directory to hold scripts (. py or. cgi) that you write

2 Execute python-m cgihttpserver in the directory where Cgi-bin is located , start the server

3 in the browser input IP:8000/cgi-bin/xxx.py can call xxx.py script in Cgi-bin directory (Linux may want to change permissions 755)

Example 1

hello.py

#!/usr/bin/python #for Linux# -*-coding:utf-8-*-print" content-type:text/html\r\n\r\n" #HTTP的header \r\n\r\n Means the end of the head, the contents of the back are bodyprint " " "


Headers
Head Description
Content-type: The MIME information for the request that corresponds to the entity. Example: content-type:text/html
Expires:date Date and time when the response expires
Location:url Used to redirect the receiver to the location of the non-request URL to complete the request or identify the new resource
Last-modified:date Requested last modified time for resource
Content-length:n The requested content length
Set-cookie:string Set HTTP Cookies

Python CGI programming and Cgihttpserver

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.