First I must admit that I'm not an expert in either python or in the django template (jinja) language so if I missed something Im sorry about that.
I wrote a simple python dict to hold additional data which has the following code:
all_dividend_tx_additional_info[company] =
{'date': dividend.time_of_payment,
'shares': dividend.shares_owned,
'amount': dividend.amount,
'currency': dividend.currency,
'total_amount': total_amount,
'tax': tax,
'payout': payout
}
The company in the index for the dict will be filled out by the real company name in a for loop, but basically this is how it looks:
{u'BAKKA': {u'amount': Decimal('15.00'),
u'currency': u'NOK',
u'date': datetime.datetime(2018, 12, 4, 16, 0, 22, tzinfo=<UTC>),
u'payout': 180.0,
u'shares': 12,
u'tax': 55.080000000000005,
u'total_amount': Decimal('180.00')}}
However when I try to iterate over this like so:
for key, value in all_dividend_tx_additional_info.iteritems:
print key, value
I get the following error: 'builtin_function_or_method' object is not iterable
However, when I try to use this dictionary and send it off to a template it works nicely with the following syntax:
{% for key, value in all_dividend_tx_additional_info.items %}
{{ key }} - {{ value }}
Can someone explain why its iterable in a django template compared to python code ? Clearly there are differences here which I have probably missed, but I cant seem to figure out why.