Django returns an HTML error template by default when an unhandled exception happens in a view. I would like to return a JSON response instead, if the request had an “Accept: ‘application/json'” header (but otherwise return the usual HTML). How might I do that?
Django returns an HTML error template by default when an unhandled exception happens in
Share
You can specify your own 500 view function, in which you should be able to modify the response accordingly. See https://docs.djangoproject.com/en/dev/topics/http/urls/#handler500