summaryrefslogtreecommitdiff
path: root/jinja2/filters.py
diff options
context:
space:
mode:
Diffstat (limited to 'jinja2/filters.py')
-rw-r--r--jinja2/filters.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/jinja2/filters.py b/jinja2/filters.py
index 2f6ffd0..49e82aa 100644
--- a/jinja2/filters.py
+++ b/jinja2/filters.py
@@ -54,13 +54,17 @@ def environmentfilter(f):
def make_attrgetter(environment, attribute):
"""Returns a callable that looks up the given attribute from a
passed object with the rules of the environment. Dots are allowed
- to access attributes of attributes.
+ to access attributes of attributes. Integer parts in paths are
+ looked up as integers.
"""
- if not isinstance(attribute, string_types) or '.' not in attribute:
+ if not isinstance(attribute, string_types) \
+ or ('.' not in attribute and not attribute.isdigit()):
return lambda x: environment.getitem(x, attribute)
attribute = attribute.split('.')
def attrgetter(item):
for part in attribute:
+ if part.isdigit():
+ part = int(part)
item = environment.getitem(item, part)
return item
return attrgetter