diff options
| author | Tom Christie | 2012-10-10 12:15:18 +0100 |
|---|---|---|
| committer | Tom Christie | 2012-10-10 12:15:18 +0100 |
| commit | 648d2be29b0738999742f4d844caab7b7652d1ad (patch) | |
| tree | aa4b8a630231f06477e2356abcfee80d54d2c8d8 /docs | |
| parent | ccd2b0117d9c26199b1862a302b1eb06dd2f07b2 (diff) | |
| download | django-rest-framework-648d2be29b0738999742f4d844caab7b7652d1ad.tar.bz2 | |
Make sure JSON output in Browseable API is nicely indented
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/api-guide/renderers.md | 19 | ||||
| -rw-r--r-- | docs/api-guide/responses.md | 5 |
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 |
