negitoro
negitoro

Reputation: 31

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 someone 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?

Upvotes: 3

Views: 870

Answers (1)

RickyA
RickyA

Reputation: 16029

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"))

Upvotes: 3

Related Questions