我的项目中有以下视图:
class MyView(ListAPIView):
serializer_class = MySerializer
queryset = MyModel.objects.all()
paginate_by = 100
filter_class = MyFilter
renderer_classes = (XMLParser, )
当我发出get请求时,我收到此错误:
AttributeError :'XMLParser' object has no attribute 'charset'
可能是什么问题。请帮忙。
答案 0 :(得分:0)
您正在向XMLParser
元组添加renderer_classes
。 Django Rest Framework不知道如何处理它。相反,您应该将XML 渲染器添加到renderer_classes
而不是XML 分析器
class MyView(ListAPIView):
serializer_class = MySerializer
queryset = MyModel.objects.all()
paginate_by = 100
filter_class = MyFilter
renderer_classes = (XMLRenderer, )
如果您打算添加XML Parser ,则需要设置parser_classes
元组
class MyView(ListAPIView):
serializer_class = MySerializer
queryset = MyModel.objects.all()
paginate_by = 100
filter_class = MyFilter
parser_classes = (XMLParser, )