#12787: TemplateDoesNotExist exception does not report the correct template_name
-------------------------------------------+--------------------------------
Reporter: trigeek38 | Owner: anonymous
Status: reopened | Milestone: 1.2
Component: Template system | Version: SVN
Resolution: | Keywords:
TemplateDoesNotExist
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 1
Patch needs improvement: 1 |
-------------------------------------------+--------------------------------
Changes (by liorsion):
* status: closed => reopened
* needs_better_patch: 0 => 1
* resolution: fixed =>
* stage: Accepted => Unreviewed
Comment:
This fix doesn't work - the original problem remains.
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.
--
Ticket URL: <http://code.djangoproject.com/ticket/12787#comment:9>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.