Search code examples
tastypie

How should I signal to Tastypie that I cannot create a resource?


When I implement myself obj_create() in Tastypie, what is the correct way to fail (because I know for instance that some quotas are exceeded) ? I guess there is a standard exception to raise but I don't know which one.


Solution

  • By raising the ImmediateHttpResponse exception with one of the tastypie.http HttpResponse (from Django) sub-classes.

    from tastypie.exceptions import ImmediateHttpResponse
    from tastypie.http import HttpSeeOther
    
    ...
        raise ImmediateHttpResponse(HttpSeeOther())