In the previous article "What is the best way to use Python programming?" Understand the hottest Python CGI programming at the moment" We briefly introduce what Python CGI programming is. This article is to have an in-depth understanding and detailed explanation of Python cgi programming and Python cgi environment setup,
Web server support and configuration
Before you perform CGI programming, Make sure your web server supports CGI and has a CGI handler configured.
Apache supports CGI configuration:
Set 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 /var/www/cgi-bin.
The extension of CGI files is .cgi, and python can also use the .py extension.
By default, the cgi-bin directory where the Linux server is configured to run is /var/www.
If you want to specify other directories to 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. python script file ending with py:
AddHandler cgi-script .cgi .pl .py
CGI environment variables
All CGI programs receive the following environment variables, these Variables play an important role in CGI programs:
The above is the detailed content of What is Python CGI environment setup? Detailed explanation of Python cgi programming with examples. For more information, please follow other related articles on the PHP Chinese website!