summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2019-03-27 12:12:51 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-03-28 10:02:24 +0100
commitc910053a09b1831ae80ea94949ac054ac435a9ca (patch)
treeea2b2dfa8cc14434510f9361224193da7d1997e4
parent609b7f112346cc572cf3a5fd1a7c9d80ab1f1b36 (diff)
[2.2.x] Doc'd that HttpResponse accepts bytestrings.
Backport of e449c3a832ff2a4e3fa83cec6909d0476ed14110 from master
-rw-r--r--docs/ref/request-response.txt16
1 files changed, 8 insertions, 8 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 4db5162e1a..f832368c03 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -633,12 +633,13 @@ Usage
Passing strings
~~~~~~~~~~~~~~~
-Typical usage is to pass the contents of the page, as a string, to the
-:class:`HttpResponse` constructor::
+Typical usage is to pass the contents of the page, as a string or bytestring,
+to the :class:`HttpResponse` constructor::
>>> from django.http import HttpResponse
>>> response = HttpResponse("Here's the text of the Web page.")
>>> response = HttpResponse("Text only, please.", content_type="text/plain")
+ >>> response = HttpResponse(b'Bytestrings are also accepted.')
But if you want to add content incrementally, you can use ``response`` as a
file-like object::
@@ -737,16 +738,15 @@ Attributes
Methods
-------
-.. method:: HttpResponse.__init__(content='', content_type=None, status=200, reason=None, charset=None)
+.. method:: HttpResponse.__init__(content=b'', content_type=None, status=200, reason=None, charset=None)
Instantiates an ``HttpResponse`` object with the given page content and
content type.
- ``content`` should be an iterator or a string. If it's an
- iterator, it should return strings, and those strings will be
- joined together to form the content of the response. If it is not
- an iterator or a string, it will be converted to a string when
- accessed.
+ ``content`` is most commonly an iterator, bytestring, or string. Other
+ types will be converted to a bytestring by encoding their string
+ representation. Iterators should return strings or bytestrings and those
+ will be joined together to form the content of the response.
``content_type`` is the MIME type optionally completed by a character set
encoding and is used to fill the HTTP ``Content-Type`` header. If not