#15502 closed (fixed)
TemplateDoesNotExist reports incorrect template during {% include %} from Class Based Views / TemplateResponse objects
| Reported by: | James Aylett | Owned by: | nobody |
|---|---|---|---|
| Component: | Template system | Version: | 1.3-beta |
| Severity: | Keywords: | ||
| Cc: | georgedorn@… | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
If I have a django.views.generic.base.TemplateView as so:
from django.views.generic.base import TemplateView
class FailingView(TemplateView):
template_name = 'outer.html'
with templates/outer.html being:
{% include "inner.html" %}
and templates/inner.html not existing, then the exception is:
TemplateDoesNotExist at /search/ outer.html
when it should be:
TemplateDoesNotExist at /search/ inner.html
This appears to be similar to #12787, but a test case similar to test_extends_include_missing_baseloader does not show up the problem, apparently because loader.get_template() will raise the correct exception, but loader.select_template() is used with a list or tuple inside SimpleTemplateResponse.resolve_template(), and gets this wrong.
Attachments (3)
Change History (10)
by , 15 years ago
comment:1 by , 15 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
Valid problem, but not class-based view specific. As you've identified, the issue is with select_template(), which consumes the TemplateDoesNotExist error generated by the non-existence of inner.html, interprets that consumption as non-existence of the overall template, and then raises a new TemplateDoesNotExist exception because the list of provided template name (i.e., [outer.html]) couldn't be loaded.
by , 15 years ago
| Attachment: | 15502-test-and-fix.diff added |
|---|
comment:3 by , 15 years ago
| Cc: | added |
|---|---|
| Has patch: | set |
Fix added; fixed the test as well, which raised an exception due to r not being set when everything else was working great.
Also, I just realized I re-implemented the solution from #15510; but now we have a working test and a working patch in the same place at the same time.
comment:4 by , 15 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Traceback of problem