我的代码:
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数据库中,欢迎任何帮助! :)