diff options
| author | Rob Hudson | 2008-09-16 07:00:29 -0700 |
|---|---|---|
| committer | Rob Hudson | 2008-09-16 07:00:29 -0700 |
| commit | 96ca83db5686f5b8983e7b008a698307130e58c9 (patch) | |
| tree | 7dcce0b3865e3599e5e58599a8bef799b2370e3f /debug_toolbar/middleware.py | |
| parent | 4591e34f0140c43e68e4ecd97eae7f3ea05878f6 (diff) | |
| parent | 5fd534e68dbd191c5d6062a39ae512b109cccbdb (diff) | |
| download | django-debug-toolbar-96ca83db5686f5b8983e7b008a698307130e58c9.tar.bz2 | |
Merge branch 'master' into explain and updating a few bits to work with the new
urls and views.
Diffstat (limited to 'debug_toolbar/middleware.py')
| -rw-r--r-- | debug_toolbar/middleware.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index ee00448..a7e5655 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -4,6 +4,8 @@ Debug Toolbar middleware import re from django.conf import settings from django.utils.encoding import smart_str +from django.conf.urls.defaults import include, patterns +import debug_toolbar.urls from debug_toolbar.toolbar.loader import DebugToolbar _HTML_TYPES = ('text/html', 'application/xhtml+xml') @@ -31,6 +33,18 @@ class DebugToolbarMiddleware(object): if self.show_toolbar(request): self.debug_toolbar = DebugToolbar(request) self.debug_toolbar.load_panels() + + # Monkeypatch in the URLpatterns for the debug toolbar. The last item + # in the URLpatterns needs to be ```('', include(ROOT_URLCONF))``` so + # that the existing URLs load *after* the ones we patch in. However, + # this is difficult to get right: a previous middleware might have + # changed request.urlconf, so we need to pick that up instead. + original_urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF) + debug_toolbar.urls.urlpatterns += patterns('', + ('', include(original_urlconf)), + ) + request.urlconf = 'debug_toolbar.urls' + return None def process_response(self, request, response): |
