开发者

tastypie authentication / custom response

开发者 https://www.devze.com 2023-04-04 18:59 出处:网络
Are there any examples of using the APIKey authentication in tastypie. The example provided doesn\'t really go into detail on how it works.

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

精彩评论

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