[Django] #32290: TemplateNotFound if relative path passed to {% include %} in variable

3 views
Skip to first unread message

Django

unread,
Dec 21, 2020, 6:33:11 AM12/21/20
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
------------------------------------------+------------------------
Reporter: Peter Inglesby | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
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" %}
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32290>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 21, 2020, 2:09:06 PM12/21/20
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
--------------------------------+--------------------------------------

Reporter: Peter Inglesby | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "ticket_32290_tests.diff" added.

Django

unread,
Dec 21, 2020, 2:11:53 PM12/21/20
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
---------------------------------+------------------------------------

Reporter: Peter Inglesby | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* 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>

Django

unread,
Dec 27, 2020, 3:56:03 PM12/27/20
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned

Component: Template system | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* 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>

Django

unread,
Jan 27, 2021, 4:17:59 AM1/27/21
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Template system | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32290#comment:3>

Django

unread,
Jan 27, 2021, 5:37:32 AM1/27/21
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Hasan
| Ramezani
Type: Bug | Status: closed

Component: Template system | Version: 3.1
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Django

unread,
Jan 27, 2021, 5:37:32 AM1/27/21
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned

Component: Template system | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jan 27, 2021, 5:37:50 AM1/27/21
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Hasan
| Ramezani
Type: Bug | Status: closed

Component: Template system | Version: 3.1
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Dec 8, 2021, 3:12:05 AM12/8/21
to django-...@googlegroups.com
#32290: TemplateNotFound if relative path passed to {% include %} in variable
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Hasan
| Ramezani
Type: Bug | Status: closed
Component: Template system | Version: 3.1
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages