Skip to main content
100%

Creating Intercooler-friendly custom endpoints in a Django Rest Framework viewset.

✓ Published0🌍 Public
Aandybak
Last edited Apr 26, 2014
Created on Apr 26, 2014

This example shows a Django Rest Framework viewset that returns plain HTML responses for Intercooler AJAX requests while using normal content negotiation for other clients. A custom `IntercoolerContentNegotiation` class overrides `select_renderer` to check for an `ic-request` parameter in the request data, switching to `StaticHTMLRenderer` and `text/html` when present. The viewset defines two custom actions, `do_something` and `do_something_else`, each returning a simple `Response` object with a string. The code demonstrates how to integrate Intercooler’s request pattern into DRF’s renderer selection mechanism without altering the view logic.

AI-generated description

Similar vizzes