这是json
Django
回复
{
id:"123"
latitude: "37.5111",
longitude: "126.9743"
}
想要输出,就像这样:
"123": {
latitude: "37.5111",
longitude: "126.9743"
}
serializers.py
class SearchSerializer(ModelSerializer):
class Meta:
model = IpGeo
fields = [
# 'id',
# 'metadata',
'latitude',
'longitude'
]
views.py
class Search(ListAPIView):
queryset = IpGeo.objects.all()
serializer_class = SearchSerializer
答案 0 :(得分:1)
serializers.py
来自rest_framework导入序列化程序
with open(path_to_save, "wb", encoding="utf-8") as save_file:
save_file.write(data)