Commit 44cbfd78 authored by Andrew M. Kuchling's avatar Andrew M. Kuchling

[Bug #953177] Mention .getlist(); text from Paul Moore

parent 9665271f
...@@ -135,19 +135,14 @@ instance but a list of such instances. Similarly, in this situation, ...@@ -135,19 +135,14 @@ instance but a list of such instances. Similarly, in this situation,
\samp{form.getvalue(\var{key})} would return a list of strings. \samp{form.getvalue(\var{key})} would return a list of strings.
If you expect this possibility If you expect this possibility
(when your HTML form contains multiple fields with the same name), use (when your HTML form contains multiple fields with the same name), use
the \function{isinstance()} built-in function to determine whether you the \function{getlist()} function, which always returns a list of values (so that you
have a single instance or a list of instances. For example, this do not need to special-case the single item case). For example, this
code concatenates any number of username fields, separated by code concatenates any number of username fields, separated by
commas: commas:
\begin{verbatim} \begin{verbatim}
value = form.getvalue("username", "") value = form.getlist("username")
if isinstance(value, list): usernames = ",".join(value)
# Multiple username fields specified
usernames = ",".join(value)
else:
# Single or no username field specified
usernames = value
\end{verbatim} \end{verbatim}
If a field represents an uploaded file, accessing the value via the If a field represents an uploaded file, accessing the value via the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment