@@ -35,25 +35,38 @@ class DjangoTemplatePluginException(Exception):
35
35
SHOW_TRACING = False
36
36
37
37
38
- if django .VERSION >= (1 , 8 ):
39
- def check_debug ():
40
- from django .conf import settings
41
- templates = settings .TEMPLATES
38
+ def check_debug ():
39
+ """Check that Django's template debugging is enabled.
40
+
41
+ Django's built-in "template debugging" records information the plugin needs
42
+ to do its work. Check that the setting is correct, and raise an exception
43
+ if it is not.
44
+
45
+ """
46
+ # The settings for templates changed in Django 1.8 from TEMPLATE_DEBUG to
47
+ # TEMPLATES[..]['debug']. Django 1.9 tolerated both forms, 1.10 insists on
48
+ # the new form. Don't try to be version-specific here. If the new
49
+ # settings exist, use them, otherwise use the old.
50
+
51
+ from django .conf import settings
52
+ templates = getattr (settings , 'TEMPLATES' , [])
53
+ if templates :
54
+ # New-style settings.
42
55
if len (templates ) > 1 :
43
56
raise DjangoTemplatePluginException ("Can't use multiple template engines." )
44
57
template_settings = templates [0 ]
45
58
if template_settings ['BACKEND' ] != 'django.template.backends.django.DjangoTemplates' :
46
59
raise DjangoTemplatePluginException ("Can't use non-Django templates." )
47
60
if not template_settings .get ('OPTIONS' , {}).get ('debug' , False ):
48
61
raise DjangoTemplatePluginException ("Template debugging must be enabled in settings." )
49
- else :
50
- def check_debug ():
51
- from django .conf import settings
62
+ else :
63
+ # Old-style settings.
52
64
if not settings .TEMPLATE_DEBUG :
53
65
raise DjangoTemplatePluginException (
54
66
"Template debugging must be enabled in settings."
55
67
)
56
68
69
+
57
70
if django .VERSION >= (1 , 9 ):
58
71
# Since we are grabbing at internal details, we have to adapt as they
59
72
# change over versions.
0 commit comments