summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorsage <laymonage@gmail.com>2019-03-27 11:40:10 +0700
committerTim Graham <timograham@gmail.com>2019-03-29 09:43:49 -0400
commit9aa56cb0d5dede7fc176a46c745dfd3dacdad773 (patch)
tree4dfd4aed31297ccaf8b0b03e1db56cfd0e980af6 /docs/ref
parent879cc3da6249e920b8d54518a0ae06de835d7373 (diff)
Fixed #30294 -- Allowed HttpResponse to accept memoryview content.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/request-response.txt21
1 files changed, 15 insertions, 6 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 4adc20bb25..d6a336178e 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -631,13 +631,18 @@ Usage
Passing strings
~~~~~~~~~~~~~~~
-Typical usage is to pass the contents of the page, as a string or bytestring,
-to the :class:`HttpResponse` constructor::
+Typical usage is to pass the contents of the page, as a string, bytestring,
+or :class:`memoryview`, 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.')
+ >>> response = HttpResponse(memoryview(b'Memoryview as well.'))
+
+.. versionchanged:: 3.0
+
+ Support for :class:`memoryview` was added.
But if you want to add content incrementally, you can use ``response`` as a
file-like object::
@@ -741,10 +746,10 @@ Methods
Instantiates an ``HttpResponse`` object with the given page content and
content type.
- ``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`` is most commonly an iterator, bytestring, :class:`memoryview`,
+ 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
@@ -760,6 +765,10 @@ Methods
given it will be extracted from ``content_type``, and if that
is unsuccessful, the :setting:`DEFAULT_CHARSET` setting will be used.
+ .. versionchanged:: 3.0
+
+ Support for :class:`memoryview` ``content`` was added.
+
.. method:: HttpResponse.__setitem__(header, value)
Sets the given header name to the given value. Both ``header`` and