# Deprecate \`..\` in template variable lookups?

**URL:** <https://forum.djangoproject.com/t/deprecate-in-template-variable-lookups/34180>\
**Category:** Django Internals\
**Created:** [August 26, 2024, 9:26am UTC](https://forum.djangoproject.com/t/deprecate-in-template-variable-lookups/34180 "2024-08-26T09:26:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [August 26, 2024, 9:26am UTC](https://forum.djangoproject.com/t/deprecate-in-template-variable-lookups/34180/1 "2024-08-26T09:26:07Z")

</div>

I made a mistake in a template last week, typing something like `{{ book..title }}` instead of `{{ book.title }}`. This went through the normal silent failure path for variable lookups, yielding the empty string:

```auto
In [1]: from django.template import Template, Context

In [2]: Template("{{ book..title }}").render(Context({"book": {"title": "I Choose You"}}))
Out[2]: ''

```

It took me a while to spot that extra dot and remove it.

Currently, Django’s Template Engine parses `..` as a lookup for the empty string, and then another lookup. So this works:

```ipython
In [3]: Template("{{ book..title }}").render(Context({"book": {"": {"title": "I Choose You"}}}))
Out[3]: 'I Choose You'

```

That doesn’t seem particularly useful though.

Meanwhile, Jinja disallows `..` with a `TemplateSyntaxError`:

```ipython
In [4]: import jinja2

In [5]: jinja2.Template('{{ x..y }}').render({"x": {"y": 1}})
---------------------------------------------------------------------------
TemplateSyntaxError Traceback (most recent call last)
Cell In[5], line 1
----> 1 jinja2.Template('{{ x..y }}').render({"x": {"y": 1}})

...

File <unknown>:1, in template()

TemplateSyntaxError: expected name or number

```

I propose that we deprecate and remove support for `..`. I think we can do this in `Variable. __init__ ` so the warning is raised at parse time:

```diff
diff --git django/template/base.py django/template/base.py
index 0f1eca58db..1b7bccef6f 100644
--- django/template/base.py
+++ django/template/base.py
@@ -842,6 +842,8 @@ def __init__ (self, var):
                         "not begin with underscores: '%s'" % var
                     )
                 self.lookups = tuple(var.split(VARIABLE_ATTRIBUTE_SEPARATOR))
+ if "" in self.lookups:
+ warnings.warn("Uhhhhh no double dots plzzzz")
 
     def resolve(self, context):
         """Resolve this variable against a given context."""

```

What do y’all think?

---

<div class="post-metadata">

**Author:** ![carltongibson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/carltongibson/32/267_2.png) [@carltongibson](https://forum.djangoproject.com/u/carltongibson)\
**Post date:** [August 26, 2024, 9:59am UTC](https://forum.djangoproject.com/t/deprecate-in-template-variable-lookups/34180/2 "2024-08-26T09:59:58Z")

</div>

> [@adamchainz](#):
>
> That doesn’t seem particularly useful though.

Agreed. It doesn’t seem at all useful to do the empty string lookup there. 🤔

The _feature_ here is skipping undeclared variables, which is commonly done. I can’t think that folks would be deliberately leveraging this example of it though. So +1.

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [September 5, 2024, 9:43pm UTC](https://forum.djangoproject.com/t/deprecate-in-template-variable-lookups/34180/3 "2024-09-05T21:43:38Z")

</div>

I am not sure we’ll see more responses here, so I went ahead and made a ticket: [#35738 (Deprecate double-dot variable lookups) – Django](https://code.djangoproject.com/ticket/35738#ticket) .
