CGI - FieldStorage - 来自字段存储的数据 returns a MiniFieldStorage
CGI - FieldStorage - Data from field storage returns a MiniFieldStorage
我有一个 HTML 表单,其中 returns 提交了一个值。其代码如下:
<form action="/cgi-bin/filter.cgi" method = "get">Filter By Version: <input type="text" name="filter"/><input type="submit" value="submit"/></form>
CGI如下:
#!/usr/bin/python
import cgi
formData = cgi.FieldStorage()
当我打印 formData 的值时。我得到以下输出:
FieldStorage(None, None, [MiniFieldStorage('filter', '112')])
如何获取"filter"的信息?为什么我得到 "MINIFIELDSTORAGE" 中的值?
阅读 CGI
文档:https://docs.python.org/3.5/library/cgi.html
你有
value = formData['filter'].value
value = formData.getvalue('filter')
value = formData.getvalue('filter', default_value)
以及许多其他获取价值的方法。
在文档中:
... are themselves instances of FieldStorage (or MiniFieldStorage, depending on the form encoding)
和
When a form is submitted in the “old” format (as the query string or as a single data part of type application/x-www-form-urlencoded), the items will actually be instances of the class MiniFieldStorage.
query string
表示 method="GET"
而不是 method="POST"
我有一个 HTML 表单,其中 returns 提交了一个值。其代码如下:
<form action="/cgi-bin/filter.cgi" method = "get">Filter By Version: <input type="text" name="filter"/><input type="submit" value="submit"/></form>
CGI如下:
#!/usr/bin/python
import cgi
formData = cgi.FieldStorage()
当我打印 formData 的值时。我得到以下输出:
FieldStorage(None, None, [MiniFieldStorage('filter', '112')])
如何获取"filter"的信息?为什么我得到 "MINIFIELDSTORAGE" 中的值?
阅读 CGI
文档:https://docs.python.org/3.5/library/cgi.html
你有
value = formData['filter'].value
value = formData.getvalue('filter')
value = formData.getvalue('filter', default_value)
以及许多其他获取价值的方法。
在文档中:
... are themselves instances of FieldStorage (or MiniFieldStorage, depending on the form encoding)
和
When a form is submitted in the “old” format (as the query string or as a single data part of type application/x-www-form-urlencoded), the items will actually be instances of the class MiniFieldStorage.
query string
表示 method="GET"
而不是 method="POST"