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.
- Two Pi R
- Readers' Choice Awards 2013
- A Handy U-Boot Trick
- The Geek's Guide to the Coolest 2013 Holiday Gifts
- Sublime Text: One Editor to Rule Them All?
- RSS Feeds
- GIMP Shmimp, Give Me a Browser
- Raspberry Pi: the Perfect Home Server
- Tinker with Molecular Dynamics for Fun and Profit
- Linux Kernel News - October 2013
- Máy sấy quần áo
9 min 1 sec ago
- Services on GlusterFS
18 min 38 sec ago
- máy lọc nước
1 hour 9 min ago
- Máy lọc nước
1 hour 12 min ago
- Reply to comment | Linux Journal
1 hour 58 min ago
- Definitely cool stuff here
3 hours 22 sec ago
- thanks for the information
4 hours 11 min ago
- nice information thanks
4 hours 50 min ago
7 hours 45 min ago
- The lost opportunity of security
19 hours 36 min ago