aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide
diff options
context:
space:
mode:
authorTom Christie2013-05-20 21:18:17 +0100
committerTom Christie2013-05-20 21:18:17 +0100
commitaef7ac72cc49db0745edcfe083220570abbbe3a7 (patch)
treee20b06bad897714f7756f0fd468485d0652c3835 /docs/api-guide
parentf19e0d544fdcd318c2bde2057d91777beda78915 (diff)
downloaddjango-rest-framework-aef7ac72cc49db0745edcfe083220570abbbe3a7.tar.bz2
content type may be set explicitly on the response
Diffstat (limited to 'docs/api-guide')
-rw-r--r--docs/api-guide/renderers.md9
-rw-r--r--docs/api-guide/responses.md3
2 files changed, 11 insertions, 1 deletions
diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md
index fb5a5518..63641d23 100644
--- a/docs/api-guide/renderers.md
+++ b/docs/api-guide/renderers.md
@@ -300,6 +300,15 @@ For example:
data = serializer.data
return Response(data)
+## Underspecifying the media type
+
+In some cases you might want a renderer to serve a range of media types.
+In this case you can underspecify the media types it should respond to, by using a `media_type` value such as `image/*`, or `*/*`.
+
+If you underspecify the renderer's media type, you should make sure to specify the media type explictly when you return the response, using the `content_type` attribute. For example:
+
+ return Response(data, content_type='image/png')
+
## Designing your media types
For the purposes of many Web APIs, simple `JSON` responses with hyperlinked relations may be sufficient. If you want to fully embrace RESTful design and [HATEOAS] you'll need to consider the design and usage of your media types in more detail.
diff --git a/docs/api-guide/responses.md b/docs/api-guide/responses.md
index 794f9377..59632ad5 100644
--- a/docs/api-guide/responses.md
+++ b/docs/api-guide/responses.md
@@ -20,7 +20,7 @@ Unless you want to heavily customize REST framework for some reason, you should
## Response()
-**Signature:** `Response(data, status=None, template_name=None, headers=None)`
+**Signature:** `Response(data, status=None, template_name=None, headers=None, content_type=None)`
Unlike regular `HttpResponse` objects, you do not instantiate `Response` objects with rendered content. Instead you pass in unrendered data, which may consist of any python primatives.
@@ -34,6 +34,7 @@ Arguments:
* `status`: A status code for the response. Defaults to 200. See also [status codes][statuscodes].
* `template_name`: A template name to use if `HTMLRenderer` is selected.
* `headers`: A dictionary of HTTP headers to use in the response.
+* `content_type`: The content type of the response. Typically, this will be set automatically by the renderer as determined by content negotiation, but there may be some cases where you need to specify the content type explicitly.
---