Django序列化程序请求JSON值

时间:2018-04-20 07:21:25

标签: python django django-rest-framework django-serializer

使用 django 2.0.2 MAC OS 10.13

views.py

from rest_framework import serializers
from .models import register
import uuid
class RegisterSerializer(serializers.Serializer):
    UserEmail = serializers.EmailField(allow_blank=True,default=uuid.uuid4())
    UserPassword = serializers.CharField(allow_blank=True,default=uuid.uuid4())
    UserSex = serializers.IntegerField(default=0)
    UserAge = serializers.IntegerField(default=0)
    DeviceId = serializers.CharField(allow_blank=True,default=uuid.uuid4())
    PushKey = serializers.CharField(allow_blank=True,default=uuid.uuid4())
    OS = serializers.IntegerField(default=0)
    OSVersion = serializers.CharField(allow_blank=True,default=0)
    def create(self,validated_date):
        return True

serializers.py

print(json.loads(request.body))

api test.html enter image description here

我输入了这个值 成功You passed a Serializer instance as data, but probably meant to pass serialized `.data` or `.error`. representation. 如何在序列化程序中使用此值

之后

提出此异常

npm

1 个答案:

答案 0 :(得分:1)

更改此行 return Response(serializer_class)return Response(serializer_class.data)