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"))
精彩评论