From bda84372d445471ce4291547edf36fe683143b42 Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Sat, 25 Apr 2020 09:36:10 +0200 Subject: [PATCH] Fix viewsets action urls with namespaces (#7287) Use the current request's namespace to resolve action urls. --- rest_framework/viewsets.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py index cad032dd9..9cb48729e 100644 --- a/rest_framework/viewsets.py +++ b/rest_framework/viewsets.py @@ -150,6 +150,11 @@ class ViewSetMixin: Reverse the action for the given `url_name`. """ url_name = '%s-%s' % (self.basename, url_name) + namespace = None + if self.request and self.request.resolver_match: + namespace = self.request.resolver_match.namespace + if namespace: + url_name = namespace + ':' + url_name kwargs.setdefault('request', self.request) return reverse(url_name, *args, **kwargs)