Location: django.http

Represents an outgoing HTTP response, including HTTP headers, cookies and body content. For information, see the documentation.


HttpResponse(content='', mimetype=DEFAULT_CONTENT_TYPE)

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.


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


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

Dictionary Syntax

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']
>>> 'Content-Disposition' in response

File-like access

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)
Last modified 8 years ago Last modified on 10/04/2007 11:57:49 AM

Attachments (1)

Download all attachments as: .zip

Back to Top