CGI script is invoked by HTTP server to process user’s input submitted through . It is stored in the cgi-bin and can be written in several language such as bash (.cgi), python, and perl.
I came across CGI when I was finding methods to run my python file. So far, php’s exec method didn’t work for me. Tried jQuery’s POST method to call the python file also didn’t work.
<html><body> <? exec ("helloworld.py", $output); echo ($output); ?> </body></html>
I managed to run a simple python cgi code when directing the browser to http://localhost/cgi-bin/hellp.py. But before that, I had a hard time figuring out where exactly to put the python file. According to this tutorial, cgi-bin is under /var/www/. However I couldn’t find anything there. I had apache2 installed and there are some people who mentioned that cgi-bin by default is found under /usr/lib/ which turns out to be right. I created a simple cgi file using bash but it couldn’t display anything (Ref here). I tried my luck by modifying the codes to a python code and saved it as hello.py. And it works!
#!/usr/bin/python print "Content-type:text/html\r\n\r\n" print '<html>' print '<h2>Hello World!!</h2>' print '</html>'
I continue reading about CGI for Python and realize that it actually isn’t too suitable for my case because I am not processing a form. I could have processed it easier with PHP and MySQL database.
Well then, time for lunch. After lunch, there are more things to research on (like jQuery AJAX) and probably to try CherryPy thoroughly again.