Django rest-framework框架-请求数据校验

验证实例:

class UserInfoSerializer(serializers.Serializer):
	  title = serializer.CharField(error_messages={'required':'标题不能为空'})


class UserInfoView(APIView):
      def post(self,request,*args,**kwargs): 
          ser = UserInfoSerializer(data=request.data)
          if ser.is_vaild():
             print(ser.vaildated_data['title'])
          else:
             print(ser.errors)
          return HttpResponse('提交数据')

  

转载于:https://www.cnblogs.com/kuku0223/p/11350003.html

你可能感兴趣的:(Django rest-framework框架-请求数据校验)