[Tutor] converting CGI's FieldStorage to dictionary?

Lance E Sloan lsloan@umich.edu
Mon, 09 Apr 2001 12:33:14 -0400


I'm writing a series of CGIs in Python and I'm using the standard
cgi module and I've also copied DocumentTemplate out of Zope.
The problem I'm running into is that DocumentTemplate uses
dictionaries as arguments to hold template values, but cgi's
FieldStorage is not quite a dictionary.  So, this doesn't work:

	import cgi
	import DocumentTemplate

	form = cgi.FieldStorage()
	tmpl = DocumentTemplate.HTMLFile('path/to/file')
	print tmpl(mapping = form)

How can I write a function that takes my FieldStorage form as an
argument and returns a dictionary of field names to field values?
I think I may have to worry about multiple values for a field
(checkboxes), but if somebody could help me get on the right track,
I can probably account for that.  My CGIs won't be accepting files
as input, so I'm glad I don't have to worry about that, too.

Thanks in advance!

--
Lance E Sloan - lsloan@umich.edu
Univ. of Michigan, ITCS