What is good for Python programming? Learn about the hottest Python CGI programming of the moment

Source: Internet
Author: User
In the previous article, " What can python do? Python real-World application scenario parsing", a brief introduction of python ProgrammingThe role and benefits, along with the extension of knowledge points, we come to briefly introduce what is Python CGI programming.

If you want to know what a Python CGI program is, you'll need to know what a CGI

CGI is currently maintained by NCSA, and NCSA defines CGI as follows:

CGI (Common Gateway Interface), a universal Gateway interface, is a program that runs on a server such as an HTTP server, providing an interface with the client HTML page.

Web browsing

To get a better idea of how CGI works, we can click on a link or URL from the Web page:

1. Use your browser to access the URL and connect to the HTTP Web server.

2. When the Web server receives the request information, it resolves the URL and finds whether the file accessed exists on the server and returns an error message if there is the contents of the returned file.

3. The browser receives the information from the server and displays the received file or error message.

CGI programs can be Python scripts, Perl scripts, shell scripts, C or C + + programs, and so on.

CGI Frame composition

first python CGI programming

Python to create the first CGI programming , the file name is hello.py, the file is located in/var/ In the Www/cgi-bin directory, the contents are as follows:

#!/usr/bin/python#-*-coding:utf-8-*-print "content-type:text/html" Print                     # blank line, tell the server to end the head print ' 

After saving the file, modify the hello.py and modify the file permissions to 755:

chmod 755 hello.py

The above programs in the browser access http://localhost/cgi-bin/hello.py display the results as follows:

Hello world! I am the first CGI program from the Chinese web of PHP

This hello.py script is a simple Python script, the output of the first line of the script "content-type:text/html" is sent to the browser and tells the browser that the content type is "text/html".

Output a blank line with print to tell the server to end the header information.

Related Article

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.