CGi stands for common gateway interface.
-It exchange information between web server and custom script.
Web Browsing
To understand the CGI concept, let us see what happens when we click a hyper link to browse a particular web page or URL.
-Your browser contacts to the HTTP web server and demand for Urls.
-Web Server parses the URL and looks for the filename, If it finds that file then sends it back to the browser, otherwise sends an error message indicating that you requested a wrong file.
-Web browser takes response from web server and displays either the received file or error message.
However, it is possible to set up the HTTP server so that whenever a file in a certain directory is requested that file is not sent back, instead it is executed as a program, and whatever that program outputs is sent back for your browser to display. This function is called the Common Gateway Interface or CGI and the programs are called CGI scripts. These CGI programs can be a Python Script, PERL Script, Shell Script, C or C++ program, etc.
CGI file are save as .cgi extension while python file are saved as .py extension.
CGI with Python :
-Here we want to write HTML code with the python code.
It is possible ?
-Yes it is possible in two ways, either we write python code within html code or write HTML code inside python code.
Example :
print("<'html>")
print('<'head>')
print('<'title>Mycgi')
print('<'/head>')
print('<'body>')
print('<'p>Hello world by CGI program<'/p>')
print('<'/body>')
print('<'/html>')