summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorfarhan <farhanalirazaazeemi@gmail.com>2025-06-03 10:32:34 +0500
committernessita <124304+nessita@users.noreply.github.com>2025-08-14 21:53:14 -0300
commit5e06b970956af4854e970e74990cb971ba31c96b (patch)
tree59fb79f5e255298625af1ad072ad4026e64f582d /django/utils
parentfda3c1712a1eb7b20dfc91e6c9abae32bd64d081 (diff)
Fixed #36410 -- Added support for Template Partials to the Django Template Language.
Introduced `{% partialdef %}` and `{% partial %}` template tags to define and render reusable named fragments within a template file. Partials can also be accessed using the `template_name#partial_name` syntax via `get_template()`, `render()`, `{% include %}`, and other template-loading tools. Adjusted `get_template()` behavior to support partial resolution, with appropriate error handling for invalid names and edge cases. Introduced `PartialTemplate` to encapsulate partial rendering behavior. Includes tests and internal refactors to support partial context binding, exception reporting, and tag validation. Co-authored-by: Carlton Gibson <carlton@noumenal.es> Co-authored-by: Natalia <124304+nessita@users.noreply.github.com> Co-authored-by: Nick Pope <nick@nickpope.me.uk>
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/datastructures.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 7c8669a350..7118c814b5 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -345,3 +345,21 @@ class CaseInsensitiveMapping(Mapping):
"Element key %r invalid, only strings are allowed" % elem[0]
)
yield elem
+
+
+class DeferredSubDict:
+ """
+ Wrap a dict, allowing deferred access to a sub-dict under a given key.
+
+ The value at ``deferred_key`` must itself be a dict. Accessing
+ ``DeferredSubDict(parent_dict, deferred_key)[key]`` retrieves
+ ``parent_dict[deferred_key][key]`` at access time, so updates to
+ the parent dict are reflected.
+ """
+
+ def __init__(self, parent_dict, deferred_key):
+ self.parent_dict = parent_dict
+ self.deferred_key = deferred_key
+
+ def __getitem__(self, key):
+ return self.parent_dict[self.deferred_key][key]