Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#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)

ticket_32290_tests.diff (2.2 KB ) - added by Mariusz Felisiak 4 years ago.

Download all attachments as: .zip

Change History (8)

by Mariusz Felisiak, 4 years ago

Attachment: ticket_32290_tests.diff added

comment:1 by Mariusz Felisiak, 4 years ago

Component: UncategorizedTemplate system
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Thanks for this report, it works for {% extends %} but raises TemplateDoesNotExist for {% include %} (see attached tests).

comment:2 by Hasan Ramezani, 4 years ago

Has patch: set
Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:3 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 640a6e1d:

Refs #32290 -- Added {% extends %} test for relative path in variable.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In c978dd93:

Fixed #32290 -- Fixed TemplateNotFound in {% include %} tag for relative path in variable.

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 73e7bfc:

[3.2.x] Fixed #32290 -- Fixed TemplateNotFound in {% include %} tag for relative path in variable.

Backport of c978dd93fda87c6d2e965d385164c35f1a3e64b8 from master

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In 7d02fa94:

Refs #32290 -- Optimized construct_relative_path() by delay computing has_quotes.

Note: See TracTickets for help on using tickets.
Back to Top