本文整理汇总了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 == {}
示例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)
示例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
示例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
示例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]
示例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]