Home > Article > Backend Development > What is Python CGI programming? What preparations need to be made before programming?
In this article, let’s learn about python programming. Some friends may have just come into contact with the programming language python and have an understanding of the relevant aspects of python programming from entry to practice. There are relatively few. In this article, let’s talk about the relevant knowledge of python programming.
python CGL programming
What is CGL:
CGI is currently maintained by NCSA. NCSA defines CGI as follows:
CGI (Common Gateway Interface), Common Gateway Interface, is a program that runs on a server such as an HTTP server and provides an interface with the client's HTML page.
Web browsing
In order to better understand how CGI works, we can start with the process of clicking a link or URL on a web page:
1. Use your browser to access the URL and connect to the HTTP web server.
2. After receiving the request information, the web server will parse the URL and check whether the accessed file exists on the server. If the file exists, it will return the content of the file, otherwise it will return an error message.
3. The browser receives 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, etc.
The CGL architecture diagram is as follows:
Web server support and configuration
In Before you perform CGI programming, make sure that your Web server supports CGI and has configured a CGI handler.
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
The above is all the content of this article. This article mainly introduces related knowledge of programming in python. I hope you can use the information to Understand what is said above. I hope what I have described in this article will be helpful to you and make it easier for you to learn python.
For more related knowledge, please visit thePython tutorial column on the php Chinese website.
The above is the detailed content of What is Python CGI programming? What preparations need to be made before programming?. For more information, please follow other related articles on the PHP Chinese website!