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


Python renderers.BrowsableAPIRenderer方法代碼示例

本文整理匯總了Python中rest_framework.renderers.BrowsableAPIRenderer方法的典型用法代碼示例。如果您正苦於以下問題:Python renderers.BrowsableAPIRenderer方法的具體用法?Python renderers.BrowsableAPIRenderer怎麽用?Python renderers.BrowsableAPIRenderer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.renderers的用法示例。


在下文中一共展示了renderers.BrowsableAPIRenderer方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_browsable_renderer_put_render

# 需要導入模塊: from rest_framework import renderers [as 別名]
# 或者: from rest_framework.renderers import BrowsableAPIRenderer [as 別名]
def test_browsable_renderer_put_render(input_put_view, decorator):
    """
    Test, that PUT method works with BrowsableAPIRenderer
    This was not working in the past, because of `_get_serializer`
    didn't allow `instance parameter.
    """
    data = {'blah': 'blah'}
    method = 'PUT'
    request = rest_request.Request(APIRequestFactory().get('blah'))
    output_view = decorator(input_put_view)
    wrapper_cls = _get_view_class(output_view)
    test_view_instance = wrapper_cls()

    renderer = renderers.BrowsableAPIRenderer()
    renderer.accepted_media_type = None
    renderer.renderer_context = {}
    response = renderer.get_raw_data_form(
        data, test_view_instance, method, request,
    )
    assert response.data == {} 
開發者ID:apragacz,項目名稱:django-rest-registration,代碼行數:22,代碼來源:test_api_view_serializer_class_getter.py

示例2: test_should_not_cache_for_non_json_responses

# 需要導入模塊: from rest_framework import renderers [as 別名]
# 或者: from rest_framework.renderers import BrowsableAPIRenderer [as 別名]
def test_should_not_cache_for_non_json_responses(self):
        """ Verify that the decorator does not cache if the response is not json """
        def key_func(**kwargs):  # pylint: disable=unused-argument
            return 'non_json_cache_key'

        class TestView(views.APIView):
            permission_classes = [permissions.AllowAny]
            renderer_classes = [BrowsableAPIRenderer]  # Non-json responses

            @compressed_cache_response(key_func=key_func)
            def get(self, request, *args, **kwargs):
                return Response('test response')

        view_instance = TestView()
        view_instance.headers = {}  # pylint: disable=attribute-defined-outside-init
        view_instance.dispatch(request=self.request)

        # Verify nothing was cached
        self.assertEqual(cache.get('non_json_cache_key'), None) 
開發者ID:edx,項目名稱:course-discovery,代碼行數:21,代碼來源:test_cache.py

示例3: get_renderers

# 需要導入模塊: from rest_framework import renderers [as 別名]
# 或者: from rest_framework.renderers import BrowsableAPIRenderer [as 別名]
def get_renderers(self):
        """Optionally block Browsable API rendering. """
        renderers = super(WithDynamicViewSetMixin, self).get_renderers()
        if settings.ENABLE_BROWSABLE_API is False:
            return [
                r for r in renderers if not isinstance(r, BrowsableAPIRenderer)
            ]
        else:
            return renderers 
開發者ID:AltSchool,項目名稱:dynamic-rest,代碼行數:11,代碼來源:viewsets.py

示例4: get_queryset

# 需要導入模塊: from rest_framework import renderers [as 別名]
# 或者: from rest_framework.renderers import BrowsableAPIRenderer [as 別名]
def get_queryset(self):
        # This method is needed when pagination is activated and renderer is
        # `BrowsableAPIRenderer`. Because data comes from Mongo, `list()` and
        # `retrieve()` don't need Django Queryset, we only need return `None`.
        return None 
開發者ID:kobotoolbox,項目名稱:kpi,代碼行數:7,代碼來源:data.py

示例5: get_renderers

# 需要導入模塊: from rest_framework import renderers [as 別名]
# 或者: from rest_framework.renderers import BrowsableAPIRenderer [as 別名]
def get_renderers(self):
        renderers = [api_renderers.JSONRenderer]
        if self.request.user.is_staff:
            renderers += [api_renderers.BrowsableAPIRenderer]
        return [renderer() for renderer in renderers] 
開發者ID:phildini,項目名稱:logtacts,代碼行數:7,代碼來源:views.py

示例6: __init__

# 需要導入模塊: from rest_framework import renderers [as 別名]
# 或者: from rest_framework.renderers import BrowsableAPIRenderer [as 別名]
def __init__(self, *args, **kwargs):
        super(SchemaView, self).__init__(*args, **kwargs)
        if self.renderer_classes is None:
            if renderers.BrowsableAPIRenderer in api_settings.DEFAULT_RENDERER_CLASSES:
                self.renderer_classes = [
                    renderers.CoreJSONRenderer,
                    renderers.BrowsableAPIRenderer,
                ]
            else:
                self.renderer_classes = [renderers.CoreJSONRenderer] 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:12,代碼來源:views.py


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