Request Data

The request handler instance can access the request data using its request property. This is initialized to a populated WebOb Request object by the application.

The request object provides a get() method that returns values for arguments parsed from the query and from POST data. The method takes the argument name as its first parameter. For example:

class MyHandler(webapp.RequestHandler):
    def post(self):
        name = self.request.get("name")

By default, get() returns the empty string ('') if the requested argument is not in the request. If the parameter default_value is specified, get() returns the value of that parameter instead of the empty string if the argument is not present.

If the argument appears more than once in a request, get() returns the first occurrence. To get all occurrences of an argument as a possibly empty list, use get_all().

# <input name="name" type="text" />
name = self.request.get("name")

# <input name="subscribe" type="checkbox" value="yes" />
subscribe_to_newsletter = self.request.get("subscribe", default_value="no")

# <select name="favorite_foods" multiple="true">...</select>
favorite_foods = self.request.get_all("favorite_foods")
for food in favorite_foods:
  # ...

For requests with body content that is not a set of CGI parameters, such as the body of an HTTP PUT request, the request object provides the attributes body and body_file. body is the body content as a byte string. body_file provides a file-like interface to the same data.

uploaded_file = self.request.body

WebOb is an open source third-party library. See the WebOb documentation for a detailed API reference and examples.

Send feedback about...

App Engine standard environment for Python