summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorCaroline Simpson <github@hoojiboo.com>2014-04-14 17:18:03 -0400
committerTim Graham <timograham@gmail.com>2015-03-27 19:19:48 -0400
commitdc5b01ad05e50ccde688c73c2ed3334a956076b0 (patch)
tree53a0fc9a4be53387f8b625e3b6b8deceb79d22c5 /django
parent0c91a419f8de791b3051d014db3c946396138969 (diff)
downloaddjango-dc5b01ad05e50ccde688c73c2ed3334a956076b0.tar.gz
Fixed #18773 -- Added logging for template variable resolving
Added a django.template logger without a default handler. Added logging if there is an exception while resolving variables in a template.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/helpers.py1
-rw-r--r--django/template/base.py7
-rw-r--r--django/template/context.py1
3 files changed, 9 insertions, 0 deletions
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index b44d411828..a841a5e6a8 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -121,6 +121,7 @@ class AdminField(object):
self.field = form[field] # A django.forms.BoundField instance
self.is_first = is_first # Whether this field is first on the line
self.is_checkbox = isinstance(self.field.field.widget, forms.CheckboxInput)
+ self.is_readonly = False
def label_tag(self):
classes = []
diff --git a/django/template/base.py b/django/template/base.py
index c008ac623d..a29f1332a8 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -51,6 +51,7 @@ u'<html></html>'
from __future__ import unicode_literals
+import logging
import re
import warnings
from functools import partial
@@ -125,6 +126,8 @@ libraries = {}
# global list of libraries to load by default for a new parser
builtins = []
+logger = logging.getLogger('django.template')
+
class TemplateSyntaxError(Exception):
pass
@@ -209,6 +212,7 @@ class Template(object):
try:
if context.template is None:
with context.bind_template(self):
+ context.template_name = self.name
return self._render(context)
else:
return self._render(context)
@@ -893,6 +897,9 @@ class Variable(object):
else:
raise
except Exception as e:
+ template_name = getattr(context, 'template_name', 'unknown')
+ logger.debug('{} - {}'.format(template_name, e))
+
if getattr(e, 'silent_variable_failure', False):
current = context.template.engine.string_if_invalid
else:
diff --git a/django/template/context.py b/django/template/context.py
index 2c30181927..2434b31a68 100644
--- a/django/template/context.py
+++ b/django/template/context.py
@@ -141,6 +141,7 @@ class Context(BaseContext):
self._current_app = current_app
self.use_l10n = use_l10n
self.use_tz = use_tz
+ self.template_name = "unknown"
self.render_context = RenderContext()
# Set to the original template -- as opposed to extended or included
# templates -- during rendering, see bind_template.