本文整理匯總了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