File tree Expand file tree Collapse file tree 5 files changed +36
-6
lines changed
debug_toolbar/panels/templates Expand file tree Collapse file tree 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):
2727 template_name = request .GET .get ("template" , template_origin_name )
2828
2929 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 )
3134
32- for loader in loaders :
3335 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)
3740 if hasattr (loader , "loaders" ):
38- final_loaders += loader .loaders
41+ loaders . extend ( loader .loaders )
3942 else :
4043 final_loaders .append (loader )
4144
Original file line number Diff line number Diff line change 77* Added hook to RedirectsPanel for subclass customization.
88* Added feature to sanitize sensitive data in the Request Panel.
99* 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.
1013
11145.1.0 (2025-03-20)
1215------------------
Original file line number Diff line number Diff line change @@ -132,6 +132,24 @@ def test_lazyobject_eval(self):
132132 self .panel .generate_stats (self .request , response )
133133 self .assertIn ("lazy_value" , self .panel .content )
134134
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+
135153
136154@override_settings (
137155 DEBUG = True , DEBUG_TOOLBAR_PANELS = ["debug_toolbar.panels.templates.TemplatesPanel" ]
Original file line number Diff line number Diff line change 77
88# Quick-start development settings - unsuitable for production
99
10+ DEBUG = False
1011SECRET_KEY = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
1112
1213INTERNAL_IPS = ["127.0.0.1" ]
2728 "django.contrib.messages" ,
2829 "django.contrib.staticfiles" ,
2930 "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" ,
3035 "tests" ,
3136]
3237
Original file line number Diff line number Diff line change 2626 selenium>=4.8.0
2727 sqlparse
2828 django-csp
29+ django-template-partials
2930passenv =
3031 CI
3132 COVERAGE_ARGS
You can’t perform that action at this time.
0 commit comments