Ever wanted to use the flexibility of python on a web page?Well,try Python CGI.If we are like minded,you will love it.The pages on internet and the python IRC discourages the use of CGI as it is old,slow technology,but I am yet to know why.As of now,CGI has always been kind to me.


Step 1:
Get some Python CGI and HTML basics.I would recommend Core Python Programming by Wesley J. Chun.Just the first set of code in the CGI chapter would be enough to set you.


Step 2:
You have to configure your server to "run" python scripts instead of downloading them.The net is full of configuring apache to work on cgi.If you understand how to do those,do it.Here is the simplest one available.
Else,run a server solely for CGI,which is easy(iest).Go to the directory with the cgi scripts and run the command 


python -m CGIHTTPServer


which will set the server running at the port 8000 by default.(You can specify the port at the end of the above command).For ease of access I have aliased the command to "s" by adding 


alias s='python -m CGIHTTPServer'


at end of ~/.bashrc file.

Please note that the following is compulsory for all python files
#!/usr/bin/env python  
on top of each script,for the server to recognize it as a python script.

Step 3:
Here is the final tip.....

Use the following header before every html page.This line says the browser that the incoming data is a html page.

print "Content-type: text/html\r\n\r\n"




You are all set to begin coding....

Happy coding.....