diff options
| author | Claude Paroz <claude@2xlibre.net> | 2019-11-17 13:24:10 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-01-24 14:24:59 +0100 |
| commit | d66d72f95655312c413d916add61a62928639514 (patch) | |
| tree | 575b6ab25fe1ff4e60ad4e527c8fc72f973dfb18 /docs/ref | |
| parent | cf493e5c819f5ee49b96954f026bec722e19d9c3 (diff) | |
Refs #30997 -- Added HttpRequest.accepts().
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/request-response.txt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 370993444b..2f9e78e358 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -406,6 +406,29 @@ Methods Returns ``True`` if the request is secure; that is, if it was made with HTTPS. +.. method:: HttpRequest.accepts(mime_type) + + .. versionadded:: 3.1 + + Returns ``True`` if the request ``Accept`` header matches the ``mime_type`` + argument:: + + >>> request.accepts('text/html') + True + + Most browsers send ``Accept: */*`` by default, so this would return + ``True`` for all content types. Setting an explicit ``Accept`` header in + API requests can be useful for returning a different content type for those + consumers only. See :ref:`content-negotiation-example` of using + ``accepts()`` to return different content to API consumers. + + If a response varies depending on the content of the ``Accept`` header and + you are using some form of caching like Django's :mod:`cache middleware + <django.middleware.cache>`, you should decorate the view with + :func:`vary_on_headers('Accept') + <django.views.decorators.vary.vary_on_headers>` so that the responses are + properly cached. + .. method:: HttpRequest.is_ajax() Returns ``True`` if the request was made via an ``XMLHttpRequest``, by |
