使用 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
答案 0 :(得分:1)
更改此行
return Response(serializer_class)
至
return Response(serializer_class.data)