﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25167	Provide option to disable ajax text/plain response in technical_500_response	thenewguy	nobody	"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
}}}"	New feature	closed	Error reporting	dev	Normal	duplicate			Accepted	0	0	0	0	0	0
