diff options
| author | Fabian Braun <fsbraun@gmx.de> | 2024-09-16 22:05:33 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-09-17 09:52:44 +0200 |
| commit | d2c97981fb40e0b324b064cd3561de8f5f1887b2 (patch) | |
| tree | f00654e591cd1ba878e79648f985f2a655028d88 /django/template/base.py | |
| parent | 8b9a2bf34e132ccf0ab0a074440dc55f90c76598 (diff) | |
Fixed #35735 -- Enabled template access to methods and properties of classes with __class_get_item__.
Diffstat (limited to 'django/template/base.py')
| -rw-r--r-- | django/template/base.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/django/template/base.py b/django/template/base.py index 0f1eca58db..ee2e145c04 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -880,6 +880,10 @@ class Variable: try: # catch-all for silent variable failures for bit in self.lookups: try: # dictionary lookup + # Only allow if the metaclass implements __getitem__. See + # https://docs.python.org/3/reference/datamodel.html#classgetitem-versus-getitem + if not hasattr(type(current), "__getitem__"): + raise TypeError current = current[bit] # ValueError/IndexError are for numpy.array lookup on # numpy < 1.9 and 1.9+ respectively |
