Changes between Version 1 and Version 2 of HttpResponse


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

Consise documentation

Legend:

Unmodified
Added
Removed
Modified
  • HttpResponse

    v1 v2  
    1 See http://djangoproject.com/documentation/request_response/#httpresponse-objects
     1= !HttpResponse =
     2
     3Represents an outgoing HTTP response, including HTTP headers, cookies and body content. For information, see the [http://www.djangoproject.com/documentation/request_response/#httpresponse-objects documentation].
     4
     5== Instantiation ==
     6
     7{{{
     8#!python
     9HttpResponse(content='', mimetype=DEFAULT_CONTENT_TYPE)
     10}}}
     11
     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.
     13
     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 [http://www.djangoproject.com/documentation/settings/#default-content-type project settings].
     15
     16== Attributes ==
     17
     18|| `headers` || Standard Python dictionary of HTTP headers that will be sent in the response; most useful for [http://www.djangoproject.com/documentation/middleware/ middleware] ||
     19|| `cookies` || [http://docs.python.org/lib/module-Cookie.html SimpleCookie] object containing the cookies that will be sent in the response; most useful for [http://www.djangoproject.com/documentation/middleware/ middleware] ||
     20|| `content` || A property which provides read-write access to the response body as a string only ||
     21
     22== Methods ==
     23
     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` ||
     27
     28== Dictionary Syntax ==
     29
     30!HttpResponse objects allow headers to be accessed directly on the object, using standard Python dictionary syntax.
     31
     32{{{
     33#!python
     34>>> response['Content-Disposition'] = 'attachment; filename=report.pdf'
     35>>> response['Content-Disposition']
     36'attachment; filename=report.pdf'
     37>>> del response['Content-Disposition']
     38}}}
     39
     40== File-like access ==
     41
     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 [http://www.djangoproject.com/documentation/outputting_pdf/ Outputting PDFs].
     43
     44{{{
     45#!python
     46from reportlab.pdfgen import canvas
     47pdf = canvas.Canvas(response)
     48}}}
Back to Top