Castalian
The Response Object
The Response object is used to send output back to the browser.
response.write function
response.write(string,[string,string...])
Writes string into the output stream.
response.writeln function
response.writeln(string,[string,string...])
Writes string into the output stream, followed by a newline.
response.content_type function
response.content_type(mimetype)
Changes the MIME type of the page
from its default of text/html. Useful for making a cas page
a graphic to be called in an <img> tag, or for displaying binary
documents directly out of a database.
response.addheader function
response.addheader(name,value)
Adds an additional HTTP header to the output stream. This must be called
before your page displays any HTML, or it will be ignored.
response.redirect function
response.redirect(URL)
Redirects the browser to the specified URL (with a 302 status code). This
must be called before your page displays any HTML, or it will be ignored.
response.end function
response.end()
Stops output, terminates processing of the page. Remember that this is a function,
so you need the brackets when you call it!
response.cookies dictionary
response.cookies["cookiename"] = "cookievalue"
Sets cookies. response.cookies is a fairly standard Python
dictionary. To set a cookie called "foo" to value "bar", say
response.cookies["foo"] = "bar".Advanced Cookie usage
- If you set a cookie's value to a non-string object, that object is automatically pickled (using the Python (c)Pickle module), and will be unpickled when retrieved with request.cookies. Note that this means that you can't store unpicklable objects like open file objects in a cookie.
- You can set cookie attributes other than value, to control the handling of
the cookie, by setting response.cookies[key][val] where val is chosen
from the list below (derived from RFC2109):
- "path": sets the path of the cookie away from the default
- "expires": set the cookie expiry date; the default is to have the cookie last the length of this browser session
- "comment": attach a comment to the cookie
- "domain"
- "max-age"
- "secure"
- "version"
response.cookies[cookiename] = cookievalue, otherwise it won't exist in theresponse.cookiesdictionary and you'll get a KeyError.