File tree 3 files changed +49
-0
lines changed 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):
32
32
included in the loaders.
33
33
If custom loaders are specified, then APP_DIRS must be True.
34
34
"""
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
+
35
50
app_dirs = config .get ("APP_DIRS" , False )
36
51
loaders = config .get ("OPTIONS" , {}).get ("loaders" , None )
52
+ if loaders :
53
+ loaders = list (flat_loaders (loaders ))
54
+
37
55
# By default the app loader is included.
38
56
has_app_loaders = (
39
57
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
4
4
Pending
5
5
-------
6
6
7
+ * Adjusted app directories system check to allow for nested template loaders.
8
+
7
9
4.1.0 (2023-05-15)
8
10
------------------
9
11
Original file line number Diff line number Diff line change @@ -198,3 +198,32 @@ def test_check_w006_invalid(self):
198
198
)
199
199
def test_check_w006_valid (self ):
200
200
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