Changes between Version 1 and Version 2 of HttpResponse

06/05/07 11:29:25 (8 years ago)
Marty Alchin <gulopine@…>

Consise documentation


  • HttpResponse

    v1 v2  
    1 See
     1= !HttpResponse =
     3Represents an outgoing HTTP response, including HTTP headers, cookies and body content. For information, see the [ documentation].
     5== Instantiation ==
     9HttpResponse(content='', mimetype=DEFAULT_CONTENT_TYPE)
     12The 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.
     14The 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].
     16== Attributes ==
     18|| `headers` || Standard Python dictionary of HTTP headers that will be sent in the response; most useful for [ middleware] ||
     19|| `cookies` || [ SimpleCookie] object containing the cookies that will be sent in the response; most useful for [ middleware] ||
     20|| `content` || A property which provides read-write access to the response body as a string only ||
     22== Methods ==
     24|| `has_header(key)` || Returns `True` if the given header will be sent in the response (case-insensitive), `False` otherwise ||
     25|| `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` ||
     26|| `delete_cookie(key)` || Schedules the specified cookie to be deleted when the response is sent. Addition optional arguments are available: `path='/', domain=None` ||
     28== Dictionary Syntax ==
     30!HttpResponse objects allow headers to be accessed directly on the object, using standard Python dictionary syntax.
     34>>> response['Content-Disposition'] = 'attachment; filename=report.pdf'
     35>>> response['Content-Disposition']
     36'attachment; filename=report.pdf'
     37>>> del response['Content-Disposition']
     40== File-like access ==
     42!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].
     46from reportlab.pdfgen import canvas
     47pdf = canvas.Canvas(response)
Back to Top