尝试序列化为XML会在XML中返回错误

时间:2015-02-16 20:33:01

标签: python mysql django python-2.7 django-rest-framework

我的代码:

class lista_libros(APIView):
    def post(self, request, format=None): #, format=None
        #import pdb;pdb.set_trace()
        peticion_cadena = request.data
        xml_decode = base64.b64decode(peticion_cadena)
        #root = ET.fromstring(xml_decode)
        serializer = PruebaSerializer(data = xml_decode)
        if serializer.is_valid():
            serializer.save()
        #   return Response(serializer.data)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

输出:

<?xml version="1.0" encoding="utf-8"?>
<root><non_field_errors><list-item>Invalid data. Expected a dictionary, but got str.</list-item></non_field_errors></root>

我想序列化内容数据并将其保存到我的MySQL数据库中,欢迎任何帮助! :)

0 个答案:

没有答案