The most important decorator in this module is @api_view, which is used for writing function-based views with REST framework.

There are also various decorators for setting the API policies on function based views, as well as the @detail_route and @list_route decorators, which are used to annotate methods on viewsets that should be included by routers.

Module Contents


Decorator that converts a function-based view into an APIView subclass. Takes a list of allowed methods for the view as an argument.

action(methods=None, detail=None, url_path=None, url_name=None, **kwargs)

Mark a ViewSet method as a routable action.

Set the detail boolean to determine if this action should apply to instance/detail requests or collection/list requests.

class MethodMapper(action, methods)


Enables mapping HTTP methods to different ViewSet methods for a single, logical action.

Example usage:

class MyViewSet(ViewSet):

@action(detail=False) def example(self, request, **kwargs): def create_example(self, request, **kwargs):

_map(self, method, func)
get(self, func)
post(self, func)
put(self, func)
patch(self, func)
delete(self, func)
head(self, func)
options(self, func)
trace(self, func)
detail_route(methods=None, **kwargs)

Used to mark a method on a ViewSet that should be routed for detail requests.

list_route(methods=None, **kwargs)

Used to mark a method on a ViewSet that should be routed for list requests.