當前位置: 首頁>>代碼示例>>Python>>正文


Python generics.GenericAPIView方法代碼示例

本文整理匯總了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' 
開發者ID:django-json-api,項目名稱:django-rest-framework-json-api,代碼行數:36,代碼來源:test_utils.py

示例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 
開發者ID:umutbozkurt,項目名稱:django-rest-framework-mongoengine,代碼行數:10,代碼來源:generics.py


注:本文中的rest_framework.generics.GenericAPIView方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。