当前位置: 首页>>代码示例>>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;未经允许,请勿转载。