aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar
diff options
context:
space:
mode:
authorRob Hudson2008-10-02 20:45:18 -0700
committerRob Hudson2008-10-02 20:45:18 -0700
commitb66c950d4cb8672a924f9652224772d7219abbe2 (patch)
tree9433ef78d23bb87cbb246b3168b90ce1dfef8abb /debug_toolbar
parentca2be8d277bd2f8772a7fed658507c8b47120a5e (diff)
downloaddjango-debug-toolbar-b66c950d4cb8672a924f9652224772d7219abbe2.tar.bz2
A fix for URL patterns getting appended on each request growing indefinitely.
This may break with other middleware patching urlpatterns, though.
Diffstat (limited to 'debug_toolbar')
-rw-r--r--debug_toolbar/middleware.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index 140ceba..1b2eb4d 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -22,6 +22,9 @@ class DebugToolbarMiddleware(object):
"""
def __init__(self):
self.debug_toolbar = None
+ self.original_urlconf = settings.ROOT_URLCONF
+ self.original_pattern = patterns('', ('', include(self.original_urlconf)),)
+ self.override_url = True
def show_toolbar(self, request):
if not settings.DEBUG:
@@ -33,15 +36,9 @@ class DebugToolbarMiddleware(object):
return True
def process_request(self, request):
- # 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)),
- )
+ if self.override_url:
+ debug_toolbar.urls.urlpatterns += self.original_pattern
+ self.override_url = False
request.urlconf = 'debug_toolbar.urls'
if self.show_toolbar(request):