是否有任何在tastypie中使用APIKey身份验证的示例。提供的示例并未详细说明其工作原理。
此外,我正在查看食谱,试图找到哪个钩子可以在帖子上返回自定义消息。
例如,有人发帖试图创建用户,但用户已经存在。在我的hydrate_user(self,bundle)中:我相信我会做检查但是如何返回有用的错误消息?
答案 0 :(得分:3)
你可以这样做:
from tastypie.exceptions import ImmediateHttpResponse
from tastypie.http import HttpBadRequest
if test_fails:
raise ImmediateHttpResponse(HttpBadRequest("User already exists"))