[2.2.x] Doc'd that HttpResponse accepts bytestrings.

Backport of e449c3a832 from master
This commit is contained in:
Mariusz Felisiak 2019-03-27 12:12:51 +01:00
parent 609b7f1123
commit c910053a09
No known key found for this signature in database
GPG Key ID: 2EF56372BA48CD1B
1 changed files with 8 additions and 8 deletions

View File

@ -633,12 +633,13 @@ Usage
Passing strings Passing strings
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Typical usage is to pass the contents of the page, as a string, to the Typical usage is to pass the contents of the page, as a string or bytestring,
:class:`HttpResponse` constructor:: to the :class:`HttpResponse` constructor::
>>> from django.http import HttpResponse >>> from django.http import HttpResponse
>>> response = HttpResponse("Here's the text of the Web page.") >>> response = HttpResponse("Here's the text of the Web page.")
>>> response = HttpResponse("Text only, please.", content_type="text/plain") >>> 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 But if you want to add content incrementally, you can use ``response`` as a
file-like object:: file-like object::
@ -737,16 +738,15 @@ Attributes
Methods 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 Instantiates an ``HttpResponse`` object with the given page content and
content type. content type.
``content`` should be an iterator or a string. If it's an ``content`` is most commonly an iterator, bytestring, or string. Other
iterator, it should return strings, and those strings will be types will be converted to a bytestring by encoding their string
joined together to form the content of the response. If it is not representation. Iterators should return strings or bytestrings and those
an iterator or a string, it will be converted to a string when will be joined together to form the content of the response.
accessed.
``content_type`` is the MIME type optionally completed by a character set ``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 encoding and is used to fill the HTTP ``Content-Type`` header. If not