learning python cgi

Harry G. George hgg9140 at skewer.ca.boeing.com
Fri Mar 24 15:26:46 CET 2000

python cgi's are easier if you can use the functionality of perl's
CGI.pm.  My cgipm.py module does that, giving this kind of syntax.
Also, it does the CGI.pm trick of taking debugging input from
commandline or file or stdin.

#===build query================

def sendform():
	def mkrow(name,val):
		return '<TR><TD>'+name+'</TD><TD>'+val+'</TD></TR>'

	print q.header()
	print q.start_html(title=title,author='John Doe')
	print q.tag('center',q.tag('big',q.tag('strong',title)))

	print q.hr
	print q.h1('HTML Shortcuts')
	#print q.ul(q.li('generic',q.li('tag'),q.li('start_tag','end_tag')))

	print q.ul(q.li('generic',q.ol(q.li('tag'),q.li('start_tag','end_tag')))
			   ,q.li('prebuilt',q.ol(q.li('header 1..6'),q.li('ul, ol, li'),type='a')))

	print q.hr

	print q.h1('HTML Forms')
	#---start form---
	print q.startform(action='http://wilma/cgi-bin/hgg9140/test/test02.py',
	print q.start_tag('table','border',cellspacing=2,cellpadding=5)

	print mkrow("textfield",
		  q.textfield(name="mytextfield",value="hello, world",size=50,maxlength=410))
	print mkrow("password",
		  q.password(name="mypassword",value="hello, world",size=50,maxlength=10))
	print mkrow("hidden",
		  q.hidden(name="myhidden",value="hello, world"))
	print mkrow("button",
		  q.button(label="mybutton",value="a button",onscript="xyz"))
	print mkrow("submit",
		  q.submit(label="mysubmit",value="submit now",size=20))
	print mkrow("reset",
		  q.reset(label="myreset",value="reset now",size=20))

	print mkrow("textarea",
		  q.textarea(name="mytextarea",current="hello, world\ngoodbye, world",
	print mkrow("checkboxes",

	print mkrow("radio_group",
	print mkrow("popup_menu",
	print mkrow("scrolling_list",
	#---end form---
	print q.end_tag('table')
	print q.endform()	
	print q.end_html()
def processform():

	print q.header()
	title='Test02: CGI response'
	print q.start_html(title=title,author='John Doe')
	print q.tag('center',q.tag('big',q.tag('strong',title)))


	print q.start_tag('table','border',cellspacing=2,cellpadding=5)
	print q.tr(q.th("Key"),q.th("Value"))
	for key in data.keys():
		print q.tr(q.td(key),q.td(value))
	print q.end_tag('table')
	print q.end_html()


claird at starbase.neosoft.com (Cameron Laird) writes:

> In article <38da58b9.2761140 at nntpserver.swip.net>,
> Anders Eriksson <ame at swipnet.se> wrote:
> 			.
> 			.
> 			.
> >I started using Python for a couple of months ago and I went for the
> >cgi directly. Now, as I have grown wise, I can say that was a mistake!
> >
> >Take your time learning Python first! So that you can create rather
> >complex Python applications BEFORE you start with cgi.
> >
> >CGI depends on so many things that you will get crazy trying to make
> >it do the same thing on: different OS (Unix/Windows) different web
> >servers, different browser(Navigator/IE/Opera/whatever)
> >
> >When You 'mastered' Python you can focus on how to get CGI to work.
> >There are alot of tutorials on the net (not that many using Python
> >though). There is a module in Python called cgi that does alot of
> >things for you (and alot of things strangely.)
> >
> >On the www.python.org there is a link to a tutorial on cgi...
> 			.
> 			.
> 			.
> It doesn't have to be a mistake, starting early on
> with CGI.  I quite agree that the questioner should
> familiarize himself with command-line Python usage,
> and that distractions--file system permissions, er-
> ror-handling mistakes, ...--tend to dominate CGI
> development.  However, some individuals will feel
> sufficiently comfortable with Python after as short
> a time as a day, and perhaps the questioner does not,
> at least initially, need to juggle all the combi-
> natorics typical of full-blown Web applications.
> I'm sure what you wrote is true for you.  The
> questioner, though, might be in a situation where
> he *never* chooses to create "rather complex Py-
> thon applications"; I wouldn't want him to feel
> this in any way prevents him from enjoying a little
> CGI work.
> -- 
> Cameron Laird <claird at NeoSoft.com>
> Business:  http://www.Phaseit.net
> Personal:  http://starbase.neosoft.com/~claird/home.html

Harry George                E-mail:  harry.g.george at boeing.com 
The Boeing Company          Renton:  (425) 237-6915 
P. O. Box 3707  OY-89       Everett: (425) 266-3149 
Seattle, WA 98124-2207      Page:    (425) 631-8803

More information about the Python-list mailing list