【发布时间】:2015-02-13 22:16:36
【问题描述】:
这是我的代码:
class lista_libros(APIView):
def post(self, request, format=None): #, format=None
cadena64 = request.data
xmlfile = base64.b64decode(cadena64)
#serializer = PruebaSerializer(data = xmlfile)
#if serializer.is_valid():
#serializer.save()
#return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(xmlfile)
这是我得到的:
<?xml version="1.0" encoding="utf-8"?>
<root><libro>
<nombre>Juego de tronos</nombre>
<autor>Pablo Perez.</autor>
<categoria>Fantasia</categoria>
<editorial>Mexicana</editorial>
<fecha_pub>1992</fecha_pub>
<no_pag>5000</no_pag>
</libro></root>
为什么小于和大于符号看起来像 < 和 > 而不是
此代码仅用于尝试发布 base64 字符串并将其解码为 xml 文件。
【问题讨论】:
-
您是否尝试在回复中添加
content_type="text/xml; charset=utf-8"? -
是的,我尝试过这种方式,但我仍然遇到同样的问题,当我尝试序列化它时我不能,因为 xmlfile 变量是一个字符串而不是一个 XML
-
无效数据。需要字典,但得到了字符串。
标签: python django post django-rest-framework