File tree 5 files changed +36
-6
lines changed
debug_toolbar/panels/templates
5 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -27,15 +27,18 @@ def template_source(request):
27
27
template_name = request .GET .get ("template" , template_origin_name )
28
28
29
29
final_loaders = []
30
- loaders = Engine .get_default ().template_loaders
30
+ loaders = list (Engine .get_default ().template_loaders )
31
+
32
+ while loaders :
33
+ loader = loaders .pop (0 )
31
34
32
- for loader in loaders :
33
35
if loader is not None :
34
- # When the loader has loaders associated with it,
35
- # append those loaders to the list. This occurs with
36
- # django.template.loaders.cached.Loader
36
+ # Recursively unwrap loaders until we get to loaders which do not
37
+ # themselves wrap other loaders. This adds support for
38
+ # django.template.loaders.cached.Loader and the
39
+ # django-template-partials loader (possibly among others)
37
40
if hasattr (loader , "loaders" ):
38
- final_loaders += loader .loaders
41
+ loaders . extend ( loader .loaders )
39
42
else :
40
43
final_loaders .append (loader )
41
44
Original file line number Diff line number Diff line change 7
7
* Added hook to RedirectsPanel for subclass customization.
8
8
* Added feature to sanitize sensitive data in the Request Panel.
9
9
* Fixed dark mode conflict in code block toolbar CSS
10
+ * Added support for using django-template-partials with the template panel's
11
+ source view functionality. The same change possibly adds support for other
12
+ template loaders.
10
13
11
14
5.1.0 (2025-03-20)
12
15
------------------
Original file line number Diff line number Diff line change @@ -132,6 +132,24 @@ def test_lazyobject_eval(self):
132
132
self .panel .generate_stats (self .request , response )
133
133
self .assertIn ("lazy_value" , self .panel .content )
134
134
135
+ @override_settings (
136
+ DEBUG = True ,
137
+ DEBUG_TOOLBAR_PANELS = ["debug_toolbar.panels.templates.TemplatesPanel" ],
138
+ )
139
+ def test_template_source (self ):
140
+ from django .core import signing
141
+ from django .template .loader import get_template
142
+
143
+ template = get_template ("basic.html" )
144
+ url = "/__debug__/template_source/"
145
+ data = {
146
+ "template" : template .template .name ,
147
+ "template_origin" : signing .dumps (template .template .origin .name ),
148
+ }
149
+
150
+ response = self .client .get (url , data )
151
+ self .assertEqual (response .status_code , 200 )
152
+
135
153
136
154
@override_settings (
137
155
DEBUG = True , DEBUG_TOOLBAR_PANELS = ["debug_toolbar.panels.templates.TemplatesPanel" ]
Original file line number Diff line number Diff line change 7
7
8
8
# Quick-start development settings - unsuitable for production
9
9
10
+ DEBUG = False
10
11
SECRET_KEY = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
11
12
12
13
INTERNAL_IPS = ["127.0.0.1" ]
27
28
"django.contrib.messages" ,
28
29
"django.contrib.staticfiles" ,
29
30
"debug_toolbar" ,
31
+ # We are not actively using template-partials; we just want more nesting
32
+ # in our template loader configuration, see
33
+ # https://github.com/django-commons/django-debug-toolbar/issues/2109
34
+ "template_partials" ,
30
35
"tests" ,
31
36
]
32
37
Original file line number Diff line number Diff line change 26
26
selenium>=4.8.0
27
27
sqlparse
28
28
django-csp
29
+ django-template-partials
29
30
passenv =
30
31
CI
31
32
COVERAGE_ARGS
You can’t perform that action at this time.
0 commit comments