summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2019-11-22 21:50:11 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-11-25 08:35:54 +0100
commitad56858e83c39f50612f635500a1a5df37b245d3 (patch)
tree1b509024af6efdc929da017e7e2980047acf792d /docs
parent8a8ea93b98f927d198d713b7367925f82b4d70e8 (diff)
[2.2.x] Fixed #28469 -- Doc'd how to create a custom HttpResponse subclass.
Backport of 9f1ec9efc35bbb375c9cebb3e0d8c1b7be838338 from master
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/request-response.txt14
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 8d834621cc..288fdae4f7 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -756,6 +756,8 @@ Methods
:setting:`DEFAULT_CHARSET` settings, by default: "`text/html; charset=utf-8`".
``status`` is the :rfc:`HTTP status code <7231#section-6>` for the response.
+ You can use Python's :py:class:`http.HTTPStatus` for meaningful aliases,
+ such as ``HTTPStatus.NO_CONTENT``.
``reason`` is the HTTP response phrase. If not provided, a default phrase
will be used.
@@ -958,6 +960,18 @@ types of HTTP responses. Like ``HttpResponse``, these subclasses live in
:class:`~django.template.response.SimpleTemplateResponse`, and the
``render`` method must itself return a valid response object.
+Custom response classes
+~~~~~~~~~~~~~~~~~~~~~~~
+
+If you find yourself needing a response class that Django doesn't provide, you
+can create it with the help of :py:class:`http.HTTPStatus`. For example::
+
+ from http import HTTPStatus
+ from django.http import HttpResponse
+
+ class HttpResponseNoContent(HttpResponse):
+ status_code = HTTPStatus.NO_CONTENT
+
``JsonResponse`` objects
========================