#12071 closed (wontfix)
Numeric literals like "2." are incorrectly treated as Variables
| Reported by: | Johannes Dollinger | Owned by: | nobody | 
|---|---|---|---|
| Component: | Template system | Version: | 1.1 | 
| Severity: | Keywords: | pycamp2010 | |
| Cc: | Triage Stage: | Design decision needed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
>>> Variable("2.").resolve(Context()) ... VariableDoesNotExist: Failed lookup for key [2] in u'[{}]' >>> Variable("2.").resolve(Context({"2": {"": "foo"}})) 'foo'
That should either be treated as a literal float(2) or raise TemplateSyntaxError.
Change History (7)
comment:1 by , 16 years ago
| Component: | Uncategorized → Template system | 
|---|
comment:2 by , 16 years ago
| milestone: | → 1.2 | 
|---|---|
| Triage Stage: | Unreviewed → Design decision needed | 
comment:3 by , 16 years ago
This doen't look like a bug. BTW, docs are clear: "Variable names must consist of any letter (A-Z), any digit (0-9), an underscore or a dot."
comment:4 by , 16 years ago
This is behaviour is explicitly coded in Django source code: http://code.djangoproject.com/browser/django/trunk/django/template/__init__.py#L681
comment:5 by , 16 years ago
| Keywords: | pycamp2010 added | 
|---|
comment:6 by , 16 years ago
| Resolution: | → wontfix | 
|---|---|
| Status: | new → closed | 
This is, as the comment above points out, by design; yes, Python accepts it as a float, but the Django template language isn't Python and doesn't support the same range of things.
This needs some discussion - the docs are ambiguous on whether an integer can be used as the first (or only) character in a context variable.