[Answer]-Django Tastypie 0.9.13-beta: resource always return status_code 200

1👍

I think the best way to do that is first.

create exception class:

class HTTPError(Exception):
    def __init__(self, code, msg):
        Exception.__init__(self, msg)
        self.code = code
        self.msg = msg

create a custom page “error.html” that show only err_code err_msg and request or raison if you want.
“{{err_code}} {{err_msg}} {{request}}”

dont miss to add the template in your settings.py in template

create a middleware
EXAMPLE:

class JobMiddlewareException:
    def process_exception(self, request, e):
       if isinstance(e, HTTPError)
            render_to_response('error.html', {'err_code': e.code, 'err_msg': e.msg, 'request':request}, requestcontext(request))

EXAMPLE:
and in your code when you need to raise error you do

Raise HTTPError(404, ‘Not Found. the page is not valid for user %s’ %
request.user)

Leave a comment