Changeset 1400
- Timestamp:
- 11/24/05 15:15:51 (2 years ago)
- Files:
-
- django/trunk/django/views/debug.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/views/debug.py
r1385 r1400 1 1 from django.conf import settings 2 from django.core.template import Template, Context 2 from django.core.template import Template, Context, TemplateDoesNotExist 3 3 from django.utils.html import escape 4 4 from django.utils.httpwrappers import HttpResponseServerError, HttpResponseNotFound … … 44 44 'during': during, 45 45 'after': after, 46 'top': top ,47 'bottom': bottom ,46 'top': top, 47 'bottom': bottom, 48 48 'total': total, 49 49 'line': line, … … 59 59 """ 60 60 template_info = None 61 template_does_not_exist = False 62 loader_debug_info = None 63 if issubclass(exc_type, TemplateDoesNotExist): 64 from django.core.template.loader import template_source_loaders 65 template_does_not_exist = True 66 loader_debug_info = [] 67 for loader in template_source_loaders: 68 try: 69 source_list_func = getattr(__import__(loader.__module__, '', '', ['get_template_sources']), 'get_template_sources') 70 # NOTE: This assumes exc_value is the name of the template that 71 # the loader attempted to load. 72 template_list = [{'name': t, 'exists': os.path.exists(t)} \ 73 for t in source_list_func(str(exc_value))] 74 except (ImportError, AttributeError): 75 template_list = [] 76 loader_debug_info.append({ 77 'loader': loader.__module__ + '.' + loader.__name__, 78 'templates': template_list, 79 }) 61 80 if settings.TEMPLATE_DEBUG and hasattr(exc_value, 'source'): 62 81 exc_type, exc_value, tb, template_info = get_template_exception_info(exc_type, exc_value, tb) … … 101 120 'settings': settings_dict, 102 121 'template_info': template_info, 122 'template_does_not_exist': template_does_not_exist, 123 'loader_debug_info': loader_debug_info, 103 124 }) 104 125 return HttpResponseServerError(t.render(c), mimetype='text/html') … … 188 209 #summary h2 { font-weight: normal; color: #666; } 189 210 #explanation { background:#eee; } 190 #template { background:#f6f6f6; } 211 #template, #template-not-exist { background:#f6f6f6; } 212 #template-not-exist ul { margin: 0 0 0 20px; } 191 213 #traceback { background:#eee; } 192 214 #requestinfo { background:#f6f6f6; padding-left:120px; } … … 273 295 </table> 274 296 </div> 297 {% if template_does_not_exist %} 298 <div id="template-not-exist"> 299 <h2>Template-loader postmortem</h2> 300 {% if loader_debug_info %} 301 <p>Django tried loading these templates, in this order:</p> 302 <ul> 303 {% for loader in loader_debug_info %} 304 <li>Using loader <code>{{ loader.loader }}</code>: 305 <ul>{% for t in loader.templates %}<li><code>{{ t.name }}</code> (File {% if t.exists %}exists{% else %}does not exist{% endif %})</li>{% endfor %}</ul> 306 </li> 307 {% endfor %} 308 </ul> 309 {% else %} 310 <p>Django couldn't find any templates because your <code>TEMPLATE_LOADERS</code> setting is empty!</p> 311 {% endif %} 312 </div> 313 {% endif %} 275 314 {% if template_info %} 276 315 <div id="template">
