Django-rest-framework: Traceback HTML not shown in browsable API

Created on 7 Apr 2016  ·  8Comments  ·  Source: encode/django-rest-framework

In the browsable API, when I submit a form and it causes a 500 error, the page gets reloaded instead of showing Django's 500 template.

For ajax requests, the 500 response is sent in plain text (https://github.com/django/django/blob/master/django/views/debug.py#L74) and in the browsable api, the page is redirected to itself when the response is not in HTML (https://github.com/tomchristie/django-rest-framework/blob/566812ac0b577f79801ec67f86f064cf39ebee01/rest_framework/static/rest_framework/js/ajax-form.js#L65)

It would be great to show the error details somehow.

Bug

Most helpful comment

@anoopmalav thanks for the comment there, very helpful when reviewing this! Good work folks. ✨

All 8 comments

I'm also hitting this problem. Whenever I'm doing POST/PUT requests in browsable API and it fails with 500 then a GET request is automatically fired against the same url and that's what I'm going to see in the browser. The stack trace is still logged in my log file.

Also if GET request fails then the correct django full debug/stacktrace error page is shows and no extra requests are fired. Have not been able to figure out the problem

Running django 1.7.x and rest 3.3.3

After migrating from django 1.7.1 / rest 2.3.13 to django 1.8.12 / rest 3.3.3
I encounter the same pb

Agree that this would be an improvement, yup.

I have added a patch for this. Please share your thoughts. https://github.com/tomchristie/django-rest-framework/pull/4172

@akarambir Not convinced that'd actually fix things, as I don't think it's where the issue is, tho I could be wrong. If you've confirmed that the change does result in fixing the required behavior then I'll reopen as described on the ticket. Thanks!

@tomchristie Problem is in Browsable API only because Ajax Calls in Debug Mode gets response in text/plain from django and rest's xhr redirects it as it is not text/html. Please check code at following lines:

https://github.com/django/django/blob/stable/1.10.x/django/views/debug.py#L80

https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/static/rest_framework/js/ajax-form.js#L78

@anoopmalav - That makes sense, yup. Thanks. 👍

@anoopmalav thanks for the comment there, very helpful when reviewing this! Good work folks. ✨

Was this page helpful?
0 / 5 - 0 ratings