mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 16:40:03 +03:00
Fix route iteration in get_urls
This commit is contained in:
parent
64dcb23852
commit
2096cc97dd
|
@ -251,21 +251,15 @@ class SimpleRouter(BaseRouter):
|
||||||
lookup = self.get_lookup_regex(viewset)
|
lookup = self.get_lookup_regex(viewset)
|
||||||
routes = self.get_routes(viewset)
|
routes = self.get_routes(viewset)
|
||||||
|
|
||||||
|
is_viewset = isclass(viewset) and issubclass(viewset, ViewSetMixin)
|
||||||
|
|
||||||
for route in routes:
|
for route in routes:
|
||||||
|
|
||||||
if isinstance(viewset, View):
|
if is_viewset:
|
||||||
# `viewset` is a Django CBV. REST Frameworks `ViewSet`s
|
|
||||||
# are included in this if-statement because `ViewSet`s
|
|
||||||
# subclass `APIView`, which subclasses `View`.
|
|
||||||
|
|
||||||
# Only actions which actually exist on the viewset will be bound
|
# Only actions which actually exist on the viewset will be bound
|
||||||
mapping = self.get_method_map(viewset, route.mapping)
|
mapping = self.get_method_map(viewset, route.mapping)
|
||||||
if not mapping:
|
if not mapping:
|
||||||
continue
|
continue
|
||||||
view = viewset.as_view(mapping, **initkwargs)
|
|
||||||
else:
|
|
||||||
# assume that `viewset` is a Django view
|
|
||||||
view = viewset
|
|
||||||
|
|
||||||
# Build the url pattern
|
# Build the url pattern
|
||||||
regex = route.url.format(
|
regex = route.url.format(
|
||||||
|
@ -287,8 +281,12 @@ class SimpleRouter(BaseRouter):
|
||||||
'detail': route.detail,
|
'detail': route.detail,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
view = viewset.as_view(mapping, **initkwargs)
|
||||||
name = route.name.format(basename=basename)
|
name = route.name.format(basename=basename)
|
||||||
django_path = re_path(regex, view, name=name)
|
django_path = re_path(regex, view, name=name)
|
||||||
|
else:
|
||||||
|
# assume that `viewset` is a Django view
|
||||||
|
django_path = path(prefix, viewset, name=prefix)
|
||||||
|
|
||||||
ret.append(django_path)
|
ret.append(django_path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user