summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeryn Knight <keryn@kerynknight.com>2021-11-30 13:07:45 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-08 08:17:54 +0100
commit7d02fa94332b43c7527c1b816787b4c560cf6bf6 (patch)
tree60320563d6a7a336aca2dc71a6bbce5f108fd933
parent547656c85027eda85a24edcab907022ce313f772 (diff)
Refs #32290 -- Optimized construct_relative_path() by delay computing has_quotes.
-rw-r--r--django/template/loader_tags.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index e0ab7b6bdd..3e770751d1 100644
--- a/django/template/loader_tags.py
+++ b/django/template/loader_tags.py
@@ -235,10 +235,6 @@ def construct_relative_path(current_template_name, relative_name):
Convert a relative path (starting with './' or '../') to the full template
name based on the current_template_name.
"""
- has_quotes = (
- (relative_name.startswith('"') and relative_name.endswith('"')) or
- (relative_name.startswith("'") and relative_name.endswith("'"))
- )
new_name = relative_name.strip('\'"')
if not new_name.startswith(('./', '../')):
# relative_name is a variable or a literal that doesn't contain a
@@ -262,6 +258,10 @@ def construct_relative_path(current_template_name, relative_name):
"same template in which the tag appears."
% (relative_name, current_template_name)
)
+ has_quotes = (
+ relative_name.startswith(('"', "'")) and
+ relative_name[0] == relative_name[-1]
+ )
return f'"{new_name}"' if has_quotes else new_name