id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 15510,Error reported when sub template is missing is wrong,Lior Sion,nobody,"I have two templates, TemplateA and TemplateB, where TemplateB is included in TemplateA: {{{ {% include ""sub/TemplateB.html"" %} }}} The view used to display this template is a DetailedView (although I believe it also happend with TemplateView): {{{ class TempView(DetailedView): template_name = ""subA/TemplateA.html"" }}} if TemplateB.html is missing, the result error page displays: {{{ TemplateDoesNotExist... subA/TemplateA.html, subA/tempview_detail.html }}} and no mention to the real missing template, TemplateB I believe it's quite like [ticket:12787], however, the fix there was wrong: it fixed {% extend %}-ed template that was missing an include, and not a template that was missing an include as reported, so I'm starting a new ticket for this. I believe this is the technical problem + solution: The original exception (found in loader.py, also in changeset:12792): {{{ raise TemplateDoesNotExist(name) }}} that's the correct line of code, however, at the same file (and same changeset:12792): {{{ except TemplateDoesNotExist: # If compiling the template we found raises TemplateDoesNotExist, back off to # returning the source and display name for the template we were asked to load. # This allows for correct identification (later) of the actual template that does # not exist. return source, display_name }}} the exception is caught but value is not used, and so we ""loose"" the exception. However, since we try to render it again, it's thrown again at the same place. This time, it's caught, but there's an error there: the original call look like this: {{{ def select_template(template_name_list): ""Given a list of template names, returns the first that can be loaded."" for template_name in template_name_list: try: return get_template(template_name) except TemplateDoesNotExist: continue # If we get here, none of the templates could be loaded raise TemplateDoesNotExist(', '.join(template_name_list)) }}} and so the exception caught there is not because the original template was not found, but because templateB was not found, but it's never recorded and identified. A possible solution: {{{ def select_template(template_name_list): ""Given a list of template names, returns the first that can be loaded."" error_list = [] for template_name in template_name_list: try: return get_template(template_name) except TemplateDoesNotExist, e: if e.message not in template_name_list: error_list.append(e.message) continue # If we get here, none of the templates could be loaded template_name_list += error_list raise TemplateDoesNotExist(', '.join(template_name_list)) }}} we need to make sure the reason for the TemplateDoesNotExist exception is not ""just"" looking for TemplateA in a wrong directory (the external loop). A different approach would be to create SubTemplateDoesNotExist exception type.",,closed,Template system,1.2,,duplicate,,Lior Sion,Unreviewed,1,0,0,0,0,0