Django-即使通过`raise exceptions.ParseError`

时间:2018-09-26 11:26:27

标签: django django-rest-framework parse-error

我希望通过raise exceptions.ParseError({'data':{},'message':'Email address already exists',"status":0})获得0或1的状态,但是我得到的是字符串值

代码

`def validate_email(self, email):

        email = get_adapter().clean_email(email)
        if allauth_settings.UNIQUE_EMAIL:
            if email and email_address_exists(email):

                # raise serializers.ValidationError({'status':0,'message':'Email address already exists'})
                raise exceptions.ParseError({'data':{'user':'nil'},'message':'Email address already exists','status':0})
        return email
`

输出

{     “数据”:{},     “ status”:“ 0”,     “ message”:“电子邮件地址已经存在” }

输出图像链接 status as string

1 个答案:

答案 0 :(得分:0)

您要在哪里显示此消息?

如果它在服务器端,我不知道为什么它不起作用,但是您可以尝试使用变量状态并将其强制转换为这样:

raise exceptions.ParseError({'data':{},'message':'Email address already exists',"status":int(status)})