Because your form has two rows for action
:
<INPUT TYPE=hidden NAME="action" VALUE="login">
<INPUT TYPE=hidden NAME="action" VALUE="register">
Then, form["action"]
be an list.
You can print out that with print(form["action"])
, i think output is ['login', 'register']
cgi.html help:
If the submitted form data contains more than one field with the same name, the object retrieved by form[key] is not a FieldStorage or MiniFieldStorage instance but a list of such instances.
Similarly, in this situation, form.getvalue(key) would return a list of strings. If you expect this possibility (when your HTML form contains multiple fields with the same name), use the getlist() method, which always returns a list of values (so that you do not need to special-case the single item case).