aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/api-guide/renderers.md19
-rw-r--r--docs/api-guide/responses.md5
2 files changed, 22 insertions, 2 deletions
diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md
index 1b266f7e..b2ebd0c7 100644
--- a/docs/api-guide/renderers.md
+++ b/docs/api-guide/renderers.md
@@ -132,7 +132,7 @@ Renders data into HTML for the Browseable API. This renderer will determine whi
## Custom renderers
-To implement a custom renderer, you should override `BaseRenderer`, set the `.media_type` and `.format` properties, and implement the `.render(self, data, media_type)` method.
+To implement a custom renderer, you should override `BaseRenderer`, set the `.media_type` and `.format` properties, and implement the `.render(self, data, media_type=None, renderer_context=None)` method.
For example:
@@ -144,11 +144,26 @@ For example:
media_type = 'text/plain'
format = 'txt'
- def render(self, data, media_type):
+ def render(self, data, media_type=None, renderer_context=None):
if isinstance(data, basestring):
return data
return smart_unicode(data)
+The arguments passed to the `.render()` method are:
+
+#### `data`
+
+The request data, as set by the `Response()` instantiation.
+
+#### `media_type=None`
+
+Optional. If provided, this is the accepted media type, as determined by the content negotiation stage. Depending on the client's `Accept:` header, this may be more specific than the renderer's `media_type` attribute, and may include media type parameters. For example `"application/json; nested=true"`.
+
+#### `renderer_context=None`
+
+Optional. If provided, this is a dictionary of contextual information provided by the view.
+By default this will include the following keys: `view`, `request`, `response`, `args`, `kwargs`.
+
---
# Advanced renderer usage
diff --git a/docs/api-guide/responses.md b/docs/api-guide/responses.md
index e0198324..b0de6824 100644
--- a/docs/api-guide/responses.md
+++ b/docs/api-guide/responses.md
@@ -82,6 +82,11 @@ The media type that was selected by the content negotiation stage.
Set automatically by the `APIView` or `@api_view` immediately before the response is returned from the view.
+## .renderer_context
+
+A dictionary of additional context information that will be passed to the renderer's `.render()` method.
+
+Set automatically by the `APIView` or `@api_view` immediately before the response is returned from the view.
[cite]: https://docs.djangoproject.com/en/dev/ref/template-response/
[statuscodes]: status-codes.md