Name
FieldStorage
Synopsis
class FieldStorage(keep_blank_values=0)
When your script instantiates a
FieldStorage instance
f, module cgi parses
the query string, and/or standard input, as appropriate. You need not
determine whether the client used the POST or GET method, as
cgi hides the distinction. Your script must
instantiate FieldStorage only once, since the
instantiation may consume standard input.
An instance f of class
FieldStorage is a mapping.
f’s keys are the
name attributes of the form’s
controls. When keep_blank_values is true,
f also includes controls whose values are
blank strings. By default, f ignores such
controls. f supplies methods
f
.has_key and
f
.keys, with normal
mapping semantics. The value for each key
n,
f
[
n
],
can be either:
A list of
kFieldStorageinstances, ifnamenoccurs more than once in the form (kis the number of occurrences ofn)A single
FieldStorageinstance, ifnamenoccurs exactly once in the form
How often a name occurs in a form depends on HTML
form rules. Groups of radio or
checkbox controls share a name,
but an entire group amounts to just one occurrence of the name.
Values in a FieldStorage instance are in turn
FieldStorage instances, to let you handle nested
forms. In practice, you don’t need such
complications. For each nested instance, just access the value (and
occasionally other attributes), ignoring potential nested-mapping
aspects. Avoid type tests: module cgi can
optimize, using instances of MiniFieldStorage, a lightweight signature-compatible ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access