mirror of https://github.com/django/django.git
[3.0.x] Fixed #28469 -- Doc'd how to create a custom HttpResponse subclass.
Backport of 9f1ec9efc3
from master
This commit is contained in:
parent
947f8e3485
commit
76e0846c90
|
@ -768,6 +768,8 @@ Methods
|
||||||
:setting:`DEFAULT_CHARSET` settings, by default: "`text/html; charset=utf-8`".
|
:setting:`DEFAULT_CHARSET` settings, by default: "`text/html; charset=utf-8`".
|
||||||
|
|
||||||
``status`` is the :rfc:`HTTP status code <7231#section-6>` for the response.
|
``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
|
``reason`` is the HTTP response phrase. If not provided, a default phrase
|
||||||
will be used.
|
will be used.
|
||||||
|
@ -971,6 +973,18 @@ types of HTTP responses. Like ``HttpResponse``, these subclasses live in
|
||||||
:class:`~django.template.response.SimpleTemplateResponse`, and the
|
:class:`~django.template.response.SimpleTemplateResponse`, and the
|
||||||
``render`` method must itself return a valid response object.
|
``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
|
``JsonResponse`` objects
|
||||||
========================
|
========================
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue