You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/docs/guides/response/response-renderers.md
+49-1
Original file line number
Diff line number
Diff line change
@@ -23,12 +23,29 @@ api = NinjaAPI(renderer=MyRenderer())
23
23
24
24
The `render` method takes the following arguments:
25
25
26
-
- request -> HttpRequest object
26
+
- request -> HttpRequest object
27
27
- data -> object that needs to be serialized
28
28
- response_status as an `int` -> the HTTP status code that will be returned to the client
29
29
30
30
You need also define the `media_type` attribute on the class to set the content-type header for the response.
31
31
32
+
## Rendering multiple content types
33
+
34
+
To create a renderer that will allow multiple different content types returned from the same API, you need to inherit `ninja.renderers.BaseDynamicRenderer` and override the `render` method. You still need to define the `media_type` but you can also define a list of prioritized media types within a `media_types` list. Like so:
35
+
36
+
```python hl_lines="5"
37
+
from ninja import NinjaAPI
38
+
from ninja.renderers import BaseDynamicRenderer
39
+
40
+
classMyDynamicRenderer(BaseDynamicRenderer):
41
+
media_type ="application/json"# Default response content type
0 commit comments