In this article, let's take a look at
python ProgrammingKnowledge, some friends may have just come into contact with Python, the programming language, for Python programming from the beginning to the relevant aspects of the practice of understanding relatively little, this article we will talk about Python programming knowledge.
Python CGL programming
What is CGL:
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.
The composition of the CGL frame is as follows :
Web server support and configuration
Before you perform CGI programming, make sure that your Web server supports CGI and a CGI-configured handler.
Apache supports CGI configuration:
Set up the CGI directory:
scriptalias/cgi-bin//var/www/cgi-bin/
All HTTP server execution CGI programs are saved in a pre-configured directory. This directory is called the CGI directory and, by convention, it is named the/var/www/cgi-bin directory.
CGI files with the. cgi,python extension can also use the. py extension.
By default, the Linux server configuration runs in the Cgi-bin directory as/var/www.
If you want to specify other directories that run CGI scripts, you can modify the httpd.conf configuration file as follows:
<directory "/var/www/cgi-bin" > allowoverride None Options +execcgi Order allow,deny allow From all</directory>
Add the. py suffix in AddHandler so that we can access the Python script file at the end of the. PY:
AddHandler cgi-script. cgi. pl. py