#25167: Provide option to disable ajax text/plain response in
technical_500_response
-------------------------------+--------------------
Reporter: thenewguy | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Line in question:
https://github.com/django/django/blob/master/django/views/debug.py#L89
Ticket #10841 from a long time ago made a change to return text/plain
responses unconditionally when the request was made via ajax. It would be
handy if this special casing of ajax requests could be disabled with a
setting or something.
I just spent the last 45 minutes tracking down why the debug error pages
were not rendering with styles on a new project I was basing on an older
one that did not exhibit the issue.
Turns out I hit this before and the approach I came up with in the past
was to monkey patch the handler and forcefully set ajax to false.
Otherwise it seems like there is a lot of code to copy and also warnings
in the source about writing error handlers. So I'd rather not, but I need
to display the error messages during development...
Below is a sample of the monkey patch. It would probably be better to
move the condition outside of the function and disable it when not in
DEBUG mode. I am going to do that now I guess, but I figure it was
worthwhile to raise the issue.
{{{
from django.conf import settings
from django.core.handlers.base import BaseHandler
handle_uncaught_exception = BaseHandler.handle_uncaught_exception
def _handle_uncaught_exception_monkey_patch(self, request, resolver,
exc_info):
if settings.DEBUG:
request.is_ajax = lambda: False
return handle_uncaught_exception(self, request, resolver, exc_info)
BaseHandler.handle_uncaught_exception =
_handle_uncaught_exception_monkey_patch
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25167>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.49e4475417485a651d603794ac4407ea%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.