Deepak S
Deepak S

Reputation: 45

CGI - FieldStorage - Data from field storage returns a MiniFieldStorage

I have an HTML form which returns a submits a single value. The code for which is as below:

<form action="/cgi-bin/filter.cgi" method = "get">Filter By Version: <input    type="text" name="filter"/><input type="submit" value="submit"/></form>

The CGI is as follows:

#!/usr/bin/python
import cgi
formData = cgi.FieldStorage()

When I print the value of formData. I get the following output:

FieldStorage(None, None, [MiniFieldStorage('filter', '112')])

How can I get the information of "filter"? Why am I getting the value in "MINIFIELDSTORAGE"?

Upvotes: 4

Views: 8103

Answers (1)

furas
furas

Reputation: 142804

Read CGI doc: https://docs.python.org/3.5/library/cgi.html

You have

value = formData['filter'].value 
value = formData.getvalue('filter')
value = formData.getvalue('filter', default_value) 

and many other methods to get value.


In doc:

... are themselves instances of FieldStorage (or MiniFieldStorage, depending on the form encoding)

and

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 means method="GET" instead of method="POST"

Upvotes: 6

Related Questions