summaryrefslogtreecommitdiff
path: root/django/http
diff options
context:
space:
mode:
Diffstat (limited to 'django/http')
-rw-r--r--django/http/response.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/http/response.py b/django/http/response.py
index abe71718f2..1dbaf46add 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -21,6 +21,7 @@ from django.http.cookie import SimpleCookie
from django.utils import timezone
from django.utils.datastructures import CaseInsensitiveMapping
from django.utils.encoding import iri_to_uri
+from django.utils.functional import cached_property
from django.utils.http import content_disposition_header, http_date
from django.utils.regex_helper import _lazy_re_compile
@@ -408,6 +409,11 @@ class HttpResponse(HttpResponseBase):
content = self.make_bytes(value)
# Create a list of properly encoded bytestrings to support write().
self._container = [content]
+ self.__dict__.pop("text", None)
+
+ @cached_property
+ def text(self):
+ return self.content.decode(self.charset or "utf-8")
def __iter__(self):
return iter(self._container)
@@ -461,6 +467,12 @@ class StreamingHttpResponse(HttpResponseBase):
)
@property
+ def text(self):
+ raise AttributeError(
+ "This %s instance has no `text` attribute." % self.__class__.__name__
+ )
+
+ @property
def streaming_content(self):
if self.is_async:
# pull to lexical scope to capture fixed reference in case