本文整理汇总了Python中rest_framework.generics.GenericAPIView方法的典型用法代码示例。如果您正苦于以下问题:Python generics.GenericAPIView方法的具体用法?Python generics.GenericAPIView怎么用?Python generics.GenericAPIView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.generics
的用法示例。
在下文中一共展示了generics.GenericAPIView方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_resource_name
# 需要导入模块: from rest_framework import generics [as 别名]
# 或者: from rest_framework.generics import GenericAPIView [as 别名]
def test_get_resource_name():
view = APIView()
context = {'view': view}
with override_settings(JSON_API_FORMAT_TYPES=None):
assert 'APIViews' == utils.get_resource_name(context), 'not formatted'
context = {'view': view}
with override_settings(JSON_API_FORMAT_TYPES='dasherize'):
assert 'api-views' == utils.get_resource_name(context), 'derived from view'
view.model = get_user_model()
assert 'users' == utils.get_resource_name(context), 'derived from view model'
view.resource_name = 'custom'
assert 'custom' == utils.get_resource_name(context), 'manually set on view'
view.response = Response(status=403)
assert 'errors' == utils.get_resource_name(context), 'handles 4xx error'
view.response = Response(status=500)
assert 'errors' == utils.get_resource_name(context), 'handles 500 error'
view = GenericAPIView()
view.serializer_class = ResourceSerializer
context = {'view': view}
assert 'users' == utils.get_resource_name(context), 'derived from serializer'
view.serializer_class.Meta.resource_name = 'rcustom'
assert 'rcustom' == utils.get_resource_name(context), 'set on serializer'
view = GenericAPIView()
view.serializer_class = NonModelResourceSerializer
context = {'view': view}
assert 'users' == utils.get_resource_name(context), 'derived from non-model serializer'
示例2: get_queryset
# 需要导入模块: from rest_framework import generics [as 别名]
# 或者: from rest_framework.generics import GenericAPIView [as 别名]
def get_queryset(self):
""
queryset = super(GenericAPIView, self).get_queryset()
if isinstance(queryset, BaseQuerySet):
queryset = queryset.all()
return queryset