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.
|Privacy Is Personal||Jul 02, 2015|
|July 2015 Issue of Linux Journal: Mobile||Jul 01, 2015|
|July 2015 Video Preview||Jul 01, 2015|
|PHP for Non-Developers||Jun 30, 2015|
|A Code Boot Camp for Underprivileged Kids||Jun 30, 2015|
|Comprehensive Identity Management and Audit for Red Hat Enterprise Linux||Jun 29, 2015|
- Privacy Is Personal
- PHP for Non-Developers
- Secure Server Deployments in Hostile Territory
- Linux Kernel 4.1 Released
- Django Templates
- Comprehensive Identity Management and Audit for Red Hat Enterprise Linux
- July 2015 Issue of Linux Journal: Mobile
- A Code Boot Camp for Underprivileged Kids
- Attack of the Drones
- Practical Books for the Most Technical People on the Planet