diff options
| author | Mathijs de Bruin <mathijs@mathijsfietst.nl> | 2013-02-24 16:41:10 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-05-21 16:59:40 +0200 |
| commit | 61a8de6f4f547518d217a5ff959cbd57bddf4bb0 (patch) | |
| tree | 4087f1bb04539351649974c3c97056370767be66 /django | |
| parent | fd961941cc1c9e7e1384af527792801f8f897d9f (diff) | |
Fixed #6412 -- More details if a template file cannot be loaded
Report more details about template files in loader postmortem.
Diffstat (limited to 'django')
| -rw-r--r-- | django/views/debug.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/django/views/debug.py b/django/views/debug.py index 10c07e8f78..209cdce8c9 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -218,6 +218,15 @@ class ExceptionReporter(object): self.exc_value = Exception('Deprecated String Exception: %r' % self.exc_type) self.exc_type = type(self.exc_value) + def format_path_status(self, path): + if not os.path.exists(path): + return "File does not exist" + if not os.path.isfile(path): + return "Not a file" + if not os.access(path, os.R_OK): + return "File is not readable" + return "File exists" + def get_traceback_data(self): "Return a Context instance containing traceback information." @@ -230,8 +239,10 @@ class ExceptionReporter(object): source_list_func = loader.get_template_sources # NOTE: This assumes exc_value is the name of the template that # the loader attempted to load. - template_list = [{'name': t, 'exists': os.path.exists(t)} \ - for t in source_list_func(str(self.exc_value))] + template_list = [{ + 'name': t, + 'status': self.format_path_status(t), + } for t in source_list_func(str(self.exc_value))] except AttributeError: template_list = [] loader_name = loader.__module__ + '.' + loader.__class__.__name__ @@ -650,7 +661,9 @@ TECHNICAL_500_TEMPLATE = """ <ul> {% for loader in loader_debug_info %} <li>Using loader <code>{{ loader.loader }}</code>: - <ul>{% for t in loader.templates %}<li><code>{{ t.name }}</code> (File {% if t.exists %}exists{% else %}does not exist{% endif %})</li>{% endfor %}</ul> + <ul> + {% for t in loader.templates %}<li><code>{{ t.name }}</code> ({{ t.status }})</li>{% endfor %} + </ul> </li> {% endfor %} </ul> @@ -753,7 +766,7 @@ Installed Middleware: {% if template_does_not_exist %}Template Loader Error: {% if loader_debug_info %}Django tried loading these templates, in this order: {% for loader in loader_debug_info %}Using loader {{ loader.loader }}: -{% for t in loader.templates %}{{ t.name }} (File {% if t.exists %}exists{% else %}does not exist{% endif %}) +{% for t in loader.templates %}{{ t.name }} ({{ t.status }}) {% endfor %}{% endfor %} {% else %}Django couldn't find any templates because your TEMPLATE_LOADERS setting is empty! {% endif %} @@ -943,7 +956,7 @@ Installed Middleware: {% if template_does_not_exist %}Template loader Error: {% if loader_debug_info %}Django tried loading these templates, in this order: {% for loader in loader_debug_info %}Using loader {{ loader.loader }}: -{% for t in loader.templates %}{{ t.name }} (File {% if t.exists %}exists{% else %}does not exist{% endif %}) +{% for t in loader.templates %}{{ t.name }} ({{ t.status }}) {% endfor %}{% endfor %} {% else %}Django couldn't find any templates because your TEMPLATE_LOADERS setting is empty! {% endif %} |
