@@ -35,25 +35,38 @@ class DjangoTemplatePluginException(Exception):
3535SHOW_TRACING = False
3636
3737
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.
4255 if len (templates ) > 1 :
4356 raise DjangoTemplatePluginException ("Can't use multiple template engines." )
4457 template_settings = templates [0 ]
4558 if template_settings ['BACKEND' ] != 'django.template.backends.django.DjangoTemplates' :
4659 raise DjangoTemplatePluginException ("Can't use non-Django templates." )
4760 if not template_settings .get ('OPTIONS' , {}).get ('debug' , False ):
4861 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.
5264 if not settings .TEMPLATE_DEBUG :
5365 raise DjangoTemplatePluginException (
5466 "Template debugging must be enabled in settings."
5567 )
5668
69+
5770if django .VERSION >= (1 , 9 ):
5871 # Since we are grabbing at internal details, we have to adapt as they
5972 # change over versions.
0 commit comments