diff --git a/rest_framework/routers.py b/rest_framework/routers.py index 2010a1138..f4d2fab38 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -278,7 +278,12 @@ class SimpleRouter(BaseRouter): if not prefix and regex[:2] == '^/': regex = '^' + regex[2:] - view = viewset.as_view(mapping, **route.initkwargs) + initkwargs = route.initkwargs.copy() + initkwargs.update({ + 'basename': basename, + }) + + view = viewset.as_view(mapping, **initkwargs) name = route.name.format(basename=basename) ret.append(url(regex, view, name=name)) diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py index 7f3c550a9..cf5f35af6 100644 --- a/rest_framework/viewsets.py +++ b/rest_framework/viewsets.py @@ -46,10 +46,14 @@ class ViewSetMixin(object): instantiated view, we need to totally reimplement `.as_view`, and slightly modify the view function that is created and returned. """ - # The suffix initkwarg is reserved for identifying the viewset type + # The suffix initkwarg is reserved for displaying the viewset type. # eg. 'List' or 'Instance'. cls.suffix = None + # Setting a basename allows a view to reverse its action urls. This + # value is provided by the router through the initkwargs. + cls.basename = None + # actions must not be empty if not actions: raise TypeError("The `actions` argument must be provided when "