Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
An instance of the Request class contains information about an incoming web request.
Request
is provided by the google.appengine.ext.webapp
module.
The Request class inherits from the WebOb Request class. Only some of the features of the WebOb Request class are discussed here. For more information, see the WebOb documentation.
The Request class provided by webapp inherits from the WebOb Request class. webapp adds several new methods for accessing arguments submitted by web forms, and extends several default behaviors.
import datetime from google.appengine.ext import webapp class MyRequestHandler(webapp.RequestHandler): def get(self): self.response.out.write(''' <html> <body> <form method="post"> <p>Name: <input type="text" name="name" /></p> <p>Favorite foods:</p> <select name="favorite_foods" multiple size="4"> <option value="apples">Apples</option> <option value="bananas">Bananas</option> <option value="carrots">Carrots</option> <option value="durians">Durians</option> </select> <p>Birth year: <input type="text" name="birth_year" /></p> <p><input type="submit" /></p> </form> </body> </html> ''') def post(self): name = self.request.get("name") favorite_foods = self.request.get_all("favorite_foods") birth_year = self.request.get_range("birth_year", min_value=1900, max_value=datetime.datetime.utcnow().year, default=1900)
In addition to several new methods described below, the webapp Request class has the following differences from WebOb Request:
unicode_errors='ignore'
decode_param_names=True
The constructor of the Request class is defined as followed:
An incoming request for a webapp application. Typically, the WSGIApplication instantiates a RequestHandler and initializes it with a Request object populated with a WSGI-compliant environment dictionary (environ).
Arguments:
The Request class provides the following methods to instances:
Returns the value of the query (URL) or POST argument with the given name. If multiple arguments have the same name, the first argument's value is returned. The URL and request body are expected to be in the standard format used by web browsers for form submission.
Arguments:
Returns a list of values of all of the query (URL) or POST arguments with the given name, possibly an empty list.
Arguments:
Returns a list of the names of query (URL) or POST data arguments. An argument name only appears once in the list, even if the data contains multiple arguments with the same name.
Parses the query (URL) or POST data argument with the given name as an int
, and returns it. The value is normalized to be within the given range, if any.
Arguments:
The following is a partial list of instance variable members inherited from the WebOb Request class. For more information, see the WebOb documentation.
?
.