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