Django rest-framework框架-组件之渲染器

渲染器:
    
from rest_framework.renderers import BrowsableAPIRenderer,AdminRenderer,HTMLFormRenderer,JSONRenderer
class TestView(APIView):
	renderer_classes = [JSONRenderer,BrowsableAPIRenderer, ] #建议只加这两个

	get(self,reuqest,*args,**kwargs):
		#获取数据  models.Role.objects.all()
		roles = self.get_queryset() 
		pager_roles = self.paginate_queryset(roles)
		#序列化
		self.get_serializer(instance=pager_roles,many=True)
		return Response(ser.data)


全局配置:
"DEFAULT_RENDERER_CLASSES": ['',
		'rest_framework.renderers.JSONRenderer',
		'rest_framework.renderers.BrowsableAPIRenderer',
],

推荐写到settings里面

  

posted @ 2019-08-14 16:16  划得戳  阅读(144)  评论(0编辑  收藏  举报