-
Notifications
You must be signed in to change notification settings - Fork 6
Prevent purely numeric template variables #116
Description
Code of Conduct
- I agree to follow Django's Code of Conduct
Feature Description
Raise a TemplateSyntaxError for template variables (and filter or template tag arguments) that start as a numeric literal. For example {{ 1.a }}, {{ 2.3.1 }}, {% if 12.3.c %}.
Problem
Django always treats a template variable like {{ 1 }} or {{ 2.3 }} as a numeric literal, so it is impossible to use a context with purely numeric keys to look up values. For example, the "foo" string in { 1: "foo"} or {"1": "foo"} can never be looked up. This means it's much more likely that an example like {{ 1.2.3 }} or {{ 1.a }} is a mistake by the template author than an intentional attempt to look up {1: {2: {3: 4}}} or {"1": {"a": "foo"}}.
I don't think we should prevent examples such as {{ 1a }}, since this can be looked up in a context such as {"1a": "foo"}.
Request or proposal
proposal
Additional Details
I talk about this in my blog post. I also opened a Trac ticket, but was redirected here.
Implementation Suggestions
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status