|Version 3 (modified by Marty Alchin <gulopine@…>, 8 years ago) (diff)|
Represents an outgoing HTTP response, including HTTP headers, cookies and body content. For information, see the documentation.
The optional content argument initializes the response with the given content. It may be a string or an iteratable object, with the items of iterables being joined together without anything in-between them.
The optional mimetype argument allows the response to be bound to a particular mime-type. If not provided, it will default to the value in your project settings.
|headers||Standard Python dictionary of HTTP headers that will be sent in the response; most useful for middleware|
|cookies||SimpleCookie object containing the cookies that will be sent in the response; most useful for middleware|
|content||A property which provides read-write access to the response body as a string only|
|has_header(key)||Returns True if the given header will be sent in the response (case-insensitive), False otherwise|
|set_cookie(key, value='')||Creates a cookie that will be set on the cilent when the response is sent. Additional optional arguments are avaialble: max_age=None, expires=None, path='/', domain=None, secure=None|
|delete_cookie(key)||Schedules the specified cookie to be deleted when the response is sent. Addition optional arguments are available: path='/', domain=None|
HttpResponse objects allow headers to be accessed directly on the object, using standard Python dictionary syntax.
>>> response['Content-Disposition'] = 'attachment; filename=report.pdf' >>> response['Content-Disposition'] 'attachment; filename=report.pdf' >>> del response['Content-Disposition']
HttpResponse objects may also be treated similarly to files, and may be used anywhere a write-only file is expected. This functionality is limited to writing to the response, and is not available if the response was created using an iterable. For an example, see Outputting PDFs.
from reportlab.pdfgen import canvas pdf = canvas.Canvas(response)