when to map http methods to view methods django rest framework

Viewed 3709

I have seen viewsets implemented like this:

can we expand on this line of code in the django rest frameworks docs:

"If we need to, we can bind this viewset into two separate views, like so:"

user_list = UserViewSet.as_view({'get': 'list'})
user_detail = UserViewSet.as_view({'get': 'retrieve'})

where would user_list and user_detail be connected to / used?

more so when would you map the http methods while using viewsets or generic views?

Because I have seen examples like this for view sets not using the mapping and using them. Example of using can we talk about how this works and how it is connected?

task_list = TaskViewSet.as_view({
    'get': 'list',
    'post': 'create'
})

task_detail = TaskViewSet.as_view({
    'get': 'retrieve',
    'put': 'update',
    'patch': 'partial_update',
    'delete': 'destroy'
})

task_router = DefaultRouter()
task_router.register(r'tasks', TaskViewSet)

and also what is up with this:

@detail_route(methods=['post'])
    def set_password(self, request, pk=None):

if we have the route decorators why do we have in url mapping? What is the difference between them?

1 Answers
Related