mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 16:40:03 +03:00
Fix issubclass for view functions
This commit is contained in:
parent
e7f6b71f75
commit
ca555ea668
|
@ -15,6 +15,7 @@ For example, you might have a `urls.py` that looks something like this:
|
||||||
"""
|
"""
|
||||||
import itertools
|
import itertools
|
||||||
from collections import OrderedDict, namedtuple
|
from collections import OrderedDict, namedtuple
|
||||||
|
from inspect import isclass
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.urls import NoReverseMatch, re_path, path
|
from django.urls import NoReverseMatch, re_path, path
|
||||||
|
@ -150,11 +151,13 @@ class SimpleRouter(BaseRouter):
|
||||||
"""
|
"""
|
||||||
# use `issubclass` and not `isinstance` because `viewset` may be an
|
# use `issubclass` and not `isinstance` because `viewset` may be an
|
||||||
# uninstantiated class.
|
# uninstantiated class.
|
||||||
if not issubclass(viewset, ViewSetMixin):
|
is_viewset = issubclass(viewset, ViewSetMixin) if isclass(viewset) else False
|
||||||
if issubclass(viewset, View):
|
if not is_viewset:
|
||||||
return [viewset.as_view(), ]
|
|
||||||
# `viewset` is not a REST Framework ViewSet,
|
# `viewset` is not a REST Framework ViewSet,
|
||||||
# so we can't dynamically generate any routes
|
# so we can't dynamically generate any routes
|
||||||
|
is_cbv = issubclass(viewset, View) if isclass(viewset) else False
|
||||||
|
if is_cbv:
|
||||||
|
return [viewset.as_view(), ]
|
||||||
return [viewset, ]
|
return [viewset, ]
|
||||||
|
|
||||||
# converting to list as iterables are good for one pass, known host needs to be checked again and again for
|
# converting to list as iterables are good for one pass, known host needs to be checked again and again for
|
||||||
|
|
Loading…
Reference in New Issue
Block a user