Home  >  Article  >  Backend Development  >  What is Python CGI environment setup? Detailed explanation of Python cgi programming with examples

What is Python CGI environment setup? Detailed explanation of Python cgi programming with examples

Tomorin
TomorinOriginal
2018-08-16 13:52:321578browse

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:

What is Python CGI environment setup? Detailed explanation of Python cgi programming with examples


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn