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.
Getting Started with DevOps - Including New Data on IT Performance from Puppet Labs 2015 State of DevOps Report
August 27, 2015
12:00 PM CDT
DevOps represents a profound change from the way most IT departments have traditionally worked: from siloed teams and high-anxiety releases to everyone collaborating on uneventful and more frequent releases of higher-quality code. It doesn't matter how large or small an organization is, or even whether it's historically slow moving or risk averse — there are ways to adopt DevOps sanely, and get measurable results in just weeks.
Free to Linux Journal readers.Register Now!
- Hacking a Safe with Bash
- Django Models and Migrations
- Secure Server Deployments in Hostile Territory, Part II
- Huge Package Overhaul for Debian and Ubuntu
- Home Automation with Raspberry Pi
- The Controversy Behind Canonical's Intellectual Property Policy
- Shashlik - a Tasty New Android Simulator
- Embed Linux in Monitoring and Control Systems
- KDE Reveals Plasma Mobile
- diff -u: What's New in Kernel Development