File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,26 @@ def check_template_config(config):
3232 included in the loaders.
3333 If custom loaders are specified, then APP_DIRS must be True.
3434 """
35+
36+ def flat_loaders (loaders ):
37+ """
38+ Recursively flatten the settings list of template loaders.
39+
40+ Check for (loader, [child_loaders]) tuples.
41+ Django's default cached loader uses this pattern.
42+ """
43+ for loader in loaders :
44+ if isinstance (loader , tuple ):
45+ yield loader [0 ]
46+ yield from flat_loaders (loader [1 ])
47+ else :
48+ yield loader
49+
3550 app_dirs = config .get ("APP_DIRS" , False )
3651 loaders = config .get ("OPTIONS" , {}).get ("loaders" , None )
52+ if loaders :
53+ loaders = list (flat_loaders (loaders ))
54+
3755 # By default the app loader is included.
3856 has_app_loaders = (
3957 loaders is None or "django.template.loaders.app_directories.Loader" in loaders
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ Change log
44Pending
55-------
66
7+ * Adjusted app directories system check to allow for nested template loaders.
8+
794.1.0 (2023-05-15)
810------------------
911
Original file line number Diff line number Diff line change @@ -198,3 +198,32 @@ def test_check_w006_invalid(self):
198198 )
199199 def test_check_w006_valid (self ):
200200 self .assertEqual (run_checks (), [])
201+
202+ @override_settings (
203+ TEMPLATES = [
204+ {
205+ "NAME" : "use_loaders" ,
206+ "BACKEND" : "django.template.backends.django.DjangoTemplates" ,
207+ "APP_DIRS" : False ,
208+ "OPTIONS" : {
209+ "context_processors" : [
210+ "django.template.context_processors.debug" ,
211+ "django.template.context_processors.request" ,
212+ "django.contrib.auth.context_processors.auth" ,
213+ "django.contrib.messages.context_processors.messages" ,
214+ ],
215+ "loaders" : [
216+ (
217+ "django.template.loaders.cached.Loader" ,
218+ [
219+ "django.template.loaders.filesystem.Loader" ,
220+ "django.template.loaders.app_directories.Loader" ,
221+ ],
222+ ),
223+ ],
224+ },
225+ },
226+ ]
227+ )
228+ def test_check_w006_valid_nested_loaders (self ):
229+ self .assertEqual (run_checks (), [])
You can’t perform that action at this time.
0 commit comments