开发者

tastypie authentication / custom response

Are there any examples of using the APIKey authentication in tastypie. The example provided doesn't really go into detail on how it works.

Also I was looking through the cookbook trying to find where there is a hook for returning custom messages on a post.

For example som开发者_StackOverfloweone does a post to try to create a user but the user already exists. In my hydrate_user(self, bundle): I believe i would do the check but how would i return a error message that is useful?


you can do that this way:

from tastypie.exceptions import ImmediateHttpResponse
from tastypie.http import HttpBadRequest

if test_fails:
    raise ImmediateHttpResponse(HttpBadRequest("User already exists"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜