我只想知道write_only
下面的选项 password1,2 字段的用法
我检查了没有密码的视图返回文件信息,所以我可以大致了解但找不到确切write_only
的选项用法。
请有人解释或留下参考文件链接..
class SignupSerializer(serializers.ModelSerializer):
password1 = serializers.CharField(write_only=True)
password2 = serializers.CharField(write_only=True)
token = serializers.SerializerMethodField()
class Meta:
model = User
fields = (
'username',
'password1',
'password2',
)
这是视图
class Signup(APIView):
def post(self, request):
serializer = SignupSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors,
status=status.HTTP_400_BAD_REQUEST)