@@ -38,8 +38,8 @@ def get_current(cls):
38
38
return cls .debug_toolbars .get (thread .get_ident ())
39
39
40
40
def __init__ (self ):
41
- self .override_url = True
42
-
41
+ self ._urlconfs = {}
42
+
43
43
# Set method to use to decide to show toolbar
44
44
self .show_toolbar = self ._show_toolbar # default
45
45
@@ -72,17 +72,27 @@ def _show_toolbar(self, request):
72
72
def process_request (self , request ):
73
73
__traceback_hide__ = True
74
74
if self .show_toolbar (request ):
75
- if self .override_url :
75
+
76
+ urlconf_name = getattr (request , 'urlconf' , settings .ROOT_URLCONF )
77
+ if urlconf_name not in self ._urlconfs :
78
+
79
+ import imp , copy
80
+
76
81
original_urlconf = __import__ (getattr (request , 'urlconf' , settings .ROOT_URLCONF ), {}, {}, ['*' ])
77
- debug_toolbar .urls .urlpatterns += patterns ('' ,
82
+ new_urlconf = imp .new_module ('urlconf' )
83
+ new_urlconf .urlpatterns = copy .copy (debug_toolbar .urls .urlpatterns )
84
+
85
+ new_urlconf .urlpatterns += patterns ('' ,
78
86
('' , include (original_urlconf )),
79
87
)
80
88
if hasattr (original_urlconf , 'handler404' ):
81
- debug_toolbar . urls .handler404 = original_urlconf .handler404
89
+ new_urlconf .handler404 = original_urlconf .handler404
82
90
if hasattr (original_urlconf , 'handler500' ):
83
- debug_toolbar .urls .handler500 = original_urlconf .handler500
84
- self .override_url = False
85
- request .urlconf = 'debug_toolbar.urls'
91
+ new_urlconf .handler500 = original_urlconf .handler500
92
+
93
+ self ._urlconfs [urlconf_name ] = new_urlconf
94
+
95
+ request .urlconf = self ._urlconfs [urlconf_name ]
86
96
87
97
toolbar = DebugToolbar (request )
88
98
for panel in toolbar .panels :
0 commit comments