你能解释一下,为什么这个代码:
from django.http import JsonResponse
from django.core import serializers
def getData(request):
arr = []
with open('test1.txt') as test1:
arr.append( test1.read() )
with open('test2.txt') as test2:
arr.append( test2.read() )
serializedData = serializers.serialize('json', arr)
return JsonResponse(serializedData)
返回此警告消息?:
“str”对象没有属性“_meta”
我只想从两个文本文件附加到一个数组内容。就这样
您不能,也不需要,在普通对象(如字符串列表)上使用 Django 序列化程序。JsonResponse
处理到 JSON 本身的转换。唯一的警告是您需要将其传递给字典,否则会收到其他错误。像这样的东西:
return JsonResponse({'arr': arr})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句