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" %}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32290>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "ticket_32290_tests.diff" added.
* type: Uncategorized => Bug
* component: Uncategorized => Template system
* stage: Unreviewed => Accepted
Comment:
Thanks for this report, it works for `{% extends %}` but raises
`TemplateDoesNotExist` for `{% include %}` (see attached tests).
--
Ticket URL: <https://code.djangoproject.com/ticket/32290#comment:1>
* owner: nobody => Hasan Ramezani
* status: new => assigned
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/13816 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/32290#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32290#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"c978dd93fda87c6d2e965d385164c35f1a3e64b8" c978dd93]:
{{{
#!CommitTicketReference repository=""
revision="c978dd93fda87c6d2e965d385164c35f1a3e64b8"
Fixed #32290 -- Fixed TemplateNotFound in {% include %} tag for relative
path in variable.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32290#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"640a6e1dce8d91e9cb1f817fadbb37a2c9d294bf" 640a6e1d]:
{{{
#!CommitTicketReference repository=""
revision="640a6e1dce8d91e9cb1f817fadbb37a2c9d294bf"
Refs #32290 -- Added {% extends %} test for relative path in variable.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32290#comment:4>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"73e7bfc8f51a68c89c4dacc7bd52072bebcabb2c" 73e7bfc]:
{{{
#!CommitTicketReference repository=""
revision="73e7bfc8f51a68c89c4dacc7bd52072bebcabb2c"
[3.2.x] Fixed #32290 -- Fixed TemplateNotFound in {% include %} tag for
relative path in variable.
Backport of c978dd93fda87c6d2e965d385164c35f1a3e64b8 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32290#comment:6>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"7d02fa94332b43c7527c1b816787b4c560cf6bf6" 7d02fa94]:
{{{
#!CommitTicketReference repository=""
revision="7d02fa94332b43c7527c1b816787b4c560cf6bf6"
Refs #32290 -- Optimized construct_relative_path() by delay computing
has_quotes.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32290#comment:7>