cgimodel: CGI Programming Made Easy with Python
Assume you already have this module:
#!/usr/bin/env python # testmethod.py def Method1(name1,name2,name3): print name1,name2,name3 if __name__ == '__main__': Method1('one','two','three')
Edit the cgidisp.py module, inserting the following method under the class Dispatcher:
def cmd_TestMeth(self,parDict): import testmethod name1 = parDict['name1'] name2 = parDict['name2'] name3 = parDict['name3'] testmethod.Method1(name1,name2,name3)Now it is ready! You can call this on the command line by typing on one line:
cgimodel.py -fun TestMeth -name1 one -name2 two -name3 threeor by URL (all on one line):
cgimodel.py?-fun=TestMeth&name1=one&name2=two&name3=threeor by FORMS:
<FORM METHOD="post" ACTION="/cgi-bin/cgimodel.py"> <INPUT TYPE=hidden name=fun value=TestMeth> <INPUT TYPE=hidden name=name1 value=one> <INPUT TYPE=hidden name=name2 value=two> <INPUT TYPE=hidden name=name3 value=three> <INPUT TYPE=SUBMIT VALUE="Run"> </FORM>It would be much better if you could separate HTML text from CGI modules, so that CGI looks thinner and more readable. You can use the template modules (see Resources) to do this. The template module keeps the text away from the CGI and has a page-paragraph structure. Each CGI call can be associated with a page, and each paragraph can be used to set up the view of your HTML page.
cgimodel can host any number of applications. The redundancy of writing a CGI front end is no longer necessary. Since many applications can be run by a single cgimodel, logging information particular to each application can be done for later analysis to improve server performance, stability of each application, better service, etc. Currently, this can be done with the log information generated by the web server.
With cgimodel.py, cgidisp.py and possibly the template.py modules, you should find writing and testing CGI programs easier.
Christine Gemuend has a degree in computer science. She is interested in parallel computers and database systems, and is working in the area of informatics.
Special Reports: DevOps
Have projects in development that need help? Have a great development operation in place that can ALWAYS be better? Regardless of where you are in your DevOps process, Linux Journal can help!
With deep focus on Collaborative Development, Continuous Testing and Release & Deployment, we offer here the DEFINITIVE DevOps for Dummies, a mobile Application Development Primer, advice & help from the experts, plus a host of other books, videos, podcasts and more. All free with a quick, one-time registration. Start browsing now...
- SUSE – “Will not diverge from its Open Source roots!”
- Dealing with Boundary Issues
- Vagrant Simplified
- Libreboot on an X60, Part I: the Setup
- System Status as SMS Text Messages
- October 2015 Issue of Linux Journal: Raspberry Pi
- Bluetooth Hacks
- Disney's Linux Light Bulbs (Not a "Luxo Jr." Reboot)
- New Products
- October 2015 Video Preview