An instance of the Response class represents the data to be sent in response to a web request.
Response
is provided by the
google.appengine.ext.webapp
module.
- Introduction
- Response()
- Class methods:
- Instance variables:
- Instance methods:
Introduction
When the webapp framework calls a request handler method, the handler instance's
response
member is initialized with an empty Response instance. The handler method prepares the response by manipulating the Response instance, such as by writing body data to the
out
member or setting headers on the
headers
member.
import datetime from google.appengine.ext import webapp class MyRequestHandler(webapp.RequestHandler): def get(self): self.response.out.write("<html><body>") self.response.out.write("<p>Welcome to the Internet!</p>") self.response.out.write("</body></html>") expires_date = datetime.datetime.utcnow() + datetime.timedelta(365) expires_str = expires_date.strftime("%d %b %Y %H:%M:%S GMT") self.response.headers.add_header("Expires", expires_str)
webapp sends the response when the handler method returns. The content of the response is the final state of the Response object when the method returns.
Note: Manipulating the object in the handler method does not communicate any data to the user. In particular, this means that webapp cannot send data to the browser then perform additional logic, as in a streaming application. (App Engine applications cannot stream data to the browser, with or without webapp.)
By default, responses use a HTTP status code of 200 ("OK"). To change the status code, the application uses the set_status() method. See also the RequestHandler object's error() method for a convenient way to set error codes.
If the response does not specify a character set in the
Content-Type
header, the character set for the response is set to UTF-8 automatically.