From b58b344edc2ea78fb2c48d07d9dfb8850e485372 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 7 Mar 2020 18:19:14 -0800 Subject: [PATCH] Add 'head' to viewset actions map --- rest_framework/viewsets.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py index 244c14d39..cad032dd9 100644 --- a/rest_framework/viewsets.py +++ b/rest_framework/viewsets.py @@ -93,6 +93,10 @@ class ViewSetMixin: def view(request, *args, **kwargs): self = cls(**initkwargs) + + if 'get' in actions and 'head' not in actions: + actions['head'] = actions['get'] + # We also store the mapping of request methods to actions, # so that we can later set the action attribute. # eg. `self.action = 'list'` on an incoming GET request. @@ -104,9 +108,6 @@ class ViewSetMixin: handler = getattr(self, action) setattr(self, method, handler) - if hasattr(self, 'get') and not hasattr(self, 'head'): - self.head = self.get - self.request = request self.args = args self.kwargs = kwargs