CGI stands for Common Gateway Interface in Python which is a set of standards that explains how information or data is exchanged between the web server and a routine script. This interface is used by web servers to route information requests supplied by a browser or we can say that CGI is customary for external gateway programs to interface with information servers such as HTTP servers.
A CGI script is invoked by an HTTP server, usually to course user input which is submitted through an HTML <FORM> or an <ISINDEX> element.
Concept of CGI
Whenever we click on a hyperlink to browse a particular web page or URL, our browser interacts with the HTTP web server and asks for the same URL (or filename). Web Server then parses the URL and looks for the same filename. If that file is found, then that file is sent back to the browser, otherwise, an error message is sent indicating that we are demanding a wrong file. Web browser takes the response from a web server and displays it, then whether it is the received file from the webserver or an error message. But, conversely, it is possible to set up the HTTP server so that whenever a specific file is requested, then that file is not sent back, but instead, it is executed as a program, and whatever that program output is, that is sent back to our browser for display. This same function is called the Common Gateway Interface (or CGI) and the programs which are executed are called CGI scripts. In python, these CGI programs is a Python Script.
Architecture of CGI:
Let us take a sample URL which passes two values to first_cgi.py program using GET method:
Below is the first_cgi.py script to handle the input given by the above sample URL. Here we will use cgi module which will makes it very easy to access the passed information
Hello, Piyush is working in GeeksforGeeks
- CGI Programming in Python
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- MySQL-Connector-Python module in Python
- Python - Read blob object in python using wand library
- Python | PRAW - Python Reddit API Wrapper
- twitter-text-python (ttp) module - Python
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- Python program to check if the list contains three consecutive common numbers in Python
- Creating and updating PowerPoint Presentations in Python using python - pptx
- How to write an empty function in Python - pass statement?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.