#32290 closed Bug (fixed)
TemplateNotFound if relative path passed to {% include %} in variable
| Reported by: | Peter Inglesby | Owned by: | Hasan Ramezani |
|---|---|---|---|
| Component: | Template system | Version: | 3.1 |
| Severity: | Normal | Keywords: | |
| Cc: | 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 you pass a template path as string literal to {% include %}, the template path can begin with eg ./, which is then resolved.
However, if you pass a template path in a variable to {% include %}, the ./ is not resolved and Django raises TemplateNotFound.
For instance, I have a template for rendering Bootstrap tab panels:
<div
class="tab-pane fade p-4"
id="{{ tab_name }}"
role="tabpanel"
aria-labelledby="{{ tab_name }}-tab"
>
{% include template_path %}
</div>
This works:
{% include "./_bootstrap_panel.html" with tab_name="search-results" template_name="myapp/_search_results.html" %}
This doesn't:
{% include "./_bootstrap_panel.html" with tab_name="search-results" template_name="./_search_results.html" %}
Attachments (1)
Change History (8)
by , 5 years ago
| Attachment: | ticket_32290_tests.diff added |
|---|
comment:1 by , 5 years ago
| Component: | Uncategorized → Template system |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
comment:3 by , 5 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
Thanks for this report, it works for
{% extends %}but raisesTemplateDoesNotExistfor{% include %}(see attached tests).