Skip to main content

Django middleware for unhandled AJAX errors

Project description

Simple Django middleware that makes it easy to view Django’s technical error page for failed AJAX requests by automagically opening them in a different browser window.

The Problem

I reckon most if not all Django developers know about Django’s useful debug-mode unhandled error page. However, when an AJAX request reaches a faulty view, the error page will not be rendered in your browser but instead be received by your AJAX error handler (assuming you even had one), which is almost always not what you want. This forces you you to find some other way to reach your traceback information. For example, before I wrote this package, I used to regularly open Chrome’s developer tools, find the failed resource in the Resources tab, and then either read through the raw HTML (yuck) or copy and paste it to a file and double click it (tedious).

Suggested Solution

Since the problem is really about ease of development, and since I (and I suspect many other Django developers) do most of my development work locally, I figured the solution can take advantage of the server being a full fledged desktop with a modern browser and a GUI. Enter ajaxerrors.middleware.ShowAJAXErrors. This little middleware intercepts all unhandled view exceptions, pickles the technical error page and uses Python’s webbrowser module to direct a new browser tab at a special URL that will serve (and delete) the previously stored page.

All this is only triggered if DEBUG is true and request.is_ajax() is true, so pretty much everything you’re used to in your development flow should stay the same. Sweet.

Installation Instructions

  1. Install like any other Python package with easy_install or pip, or simply with:

    python install

  2. Add ajaxerrors.middleware.ShowAJAXErrors to your MIDDLEWARE_CLASSES setting.

You can also find more info in the package’s readme file.


django-ajaxerrors is licensed under the MIT license, see the LICENSE file in this distribution if you’re really interested in reading all them small letters.

I’d really like to see this as a feature in Django some day, but first we should see if other people are interested and maybe add more stuff to this really simple utility. Anyway, feel free fork away and send me pull requests. I’ll do my sane best to fix any bugs for as long as… well, at least until I lose interest.

If you’d like to discuss something about django-ajaxerrors or if you are otherwise curious about me, please find me at yaniv at aknin dot name, visit django-ajaxerrors’ GitHub page or my smashing Python-centric tech blog.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-ajaxerrors-1.1.tar.gz (5.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page