diff options
| author | Tom Christie | 2012-10-05 14:22:02 +0100 |
|---|---|---|
| committer | Tom Christie | 2012-10-05 14:22:02 +0100 |
| commit | 3e862c77379b2f84356e2e8f0be20b7aca5b9e89 (patch) | |
| tree | 73b42ff68ddf94ead735b808eaa9bf567f86b04a /docs/api-guide/renderers.md | |
| parent | 6a15556384c48984868493b6b38a7afa61d77a3a (diff) | |
| download | django-rest-framework-3e862c77379b2f84356e2e8f0be20b7aca5b9e89.tar.bz2 | |
Tweak view slightly
Diffstat (limited to 'docs/api-guide/renderers.md')
| -rw-r--r-- | docs/api-guide/renderers.md | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md index f27eb360..2b1f423d 100644 --- a/docs/api-guide/renderers.md +++ b/docs/api-guide/renderers.md @@ -60,6 +60,8 @@ For example if your API serves JSON responses and the HTML browseable API, you m If your API includes views that can serve both regular webpages and API responses depending on the request, then you might consider making `TemplateHTMLRenderer` your default renderer, in order to play nicely with older browsers that send [broken accept headers][browser-accept-headers]. +--- + # API Reference ## JSONRenderer @@ -119,6 +121,8 @@ If you're building websites that use `HTMLTemplateRenderer` along with other ren 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. +--- + # Advanced renderer usage You can do some pretty flexible things using REST framework's renderers. Some examples... @@ -128,6 +132,8 @@ You can do some pretty flexible things using REST framework's renderers. Some e * Specify multiple types of HTML representation for API clients to use. * Underspecify a renderer's media type, such as using `media_type = 'image/*'`, and use the `Accept` header to vary the encoding of the response. +## Varying behaviour by media type + In some cases you might want your view to use different serialization styles depending on the accepted media type. If you need to do this you can access `request.accepted_renderer` to determine the negotiated renderer that will be used for the response. For example: |
