I am reading about templates in Jinja, especially about variables. I would like to ask you for explanation for this sentence about acessing values of the passed to Jinja syntax objects:
Implementation
For the sake of convenience, foo.bar in Jinja2 does the following things on the Python layer:
check for an attribute called bar on foo (getattr(foo, 'bar'))
if there is not, check for an item 'bar' in foo (foo.__getitem__('bar'))
if there is not, return an undefined object.
foo['bar'] works mostly the same with a small difference in sequence:
check for an item 'bar' in foo. (foo.__getitem__('bar'))
if there is not, check for an attribute called bar on foo. (getattr(foo, 'bar'))
if there is not, return an undefined object.
This is important if an object has an item and attribute with the same name. Additionally, the attr() filter only looks up attributes.
What is the difference between an item and an attribute?
PS - If it's relevant: I work on dictionaries. I have just read that Jinja enables to access the value with the key as an attribute (dict.key), however I feel confused after reading this part about the order of the processes. The comparison "key-value" pair makes understing the part above more challenging.