gpt4 book ai didi

python - 在 Tastypie 上使用自定义验证类获取错误消息

转载 作者:行者123 更新时间:2023-12-01 05:54:26 24 4
gpt4 key购买 nike

我正在尝试使用 tastypie 上的自定义验证类获取字段的错误消息。

我使用了 Tastipye 文档网站上的代码(AwesomeValidation 类):http://django-tastypie.readthedocs.org/en/latest/validation.html#implementing-your-own-validation

这是我的资源类:

class UserResource(ModelResource):                                                                                                                                             
class Meta:
queryset = User.objects.all()
resource_name = 'user'
authorization = Authorization()
validation = AwesomeValidation()

我使用 sleep 来尝试 POST 请求:

import slumber
api = slumber.API("127.0.0.1", auth=("auth", "auth"))
api.user.post({"username": "test", "password": "test", "password_confirm": "test", "email": "test@example.com"})

我收到错误 400,但没有错误消息。

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/slumber/__init__.py", line 125, in post
resp = self._request("POST", data=s.dumps(data), params=kwargs)
File "/usr/local/lib/python2.7/dist-packages/slumber/__init__.py", line 104, in _request
raise exceptions.HttpClientError("Client Error %s: %s" % (resp.status_code, url), response=resp, content=resp.content)
slumber.exceptions.HttpClientError: Client Error 400: http://127.0.0.1:8000/api/v1/user/

是否与自定义验证类有关以获取错误消息?

最佳答案

引用您的链接:

Under this validation, every field that’s a string is checked for the word ‘awesome’. If it’s not in the string, it’s an error.

关于python - 在 Tastypie 上使用自定义验证类获取错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13161029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com