简体   繁体   中英

How to fix context dict in CBV view in django?

I have this View and get context data method
View In the end of view's code i put difference dict into context key.Then i try to output all data into template, but last 3 fields are empty. 在此处输入图片说明 Here is template code: Template for view . In the end of view I print difference in.
Console prints It gives me all data I need.

[{'depos': Decimal('400000.00'), 'df': Decimal('-4600000.00'), 'pr': Decimal('-38722782.00'), 'creds': Decimal('5000000.00'), 'date': (2016, 3), 'dc': 'Створити акційні пропозиції, переглядати або створити депозитні програми'}, 
{'depos': Decimal('450776.00'), 'df': Decimal('-33783479.00'), 'pr': Decimal('-38672006.00'), 'creds': Decimal('34234255.00'), 'date': (2016, 2), 'dc': 'Створити акційні пропозиції, переглядати або створити депозитні програми'}, 
{'depos': Decimal('3473400.00'), 'df': Decimal('2973399.98'), 'pr': Decimal('-35649382.00'), 'creds': Decimal('500000.02'), 'date': (2016, 4), 'dc': 'Слід знижувати відсоткові ставки в депозитних програмах'}]

I'd like to output all fields from that dict. How to fix this issue in template/view ?

In last four statements you are not using dif but difs :

{% for dif in difs %}
    <tr>
        <td>{{ dif.depos }}</td>
        <td>{{ dif.creds }}</td>
        <td>{{ dif.date }}{{ difs.df }}</td>   <--- should be dif.df
        <td>{{ difs.df }}</td>                 <--- should be dif.df 
        <td>{{ difs.dc }}</td>                 <--- should be dif.dc 
        <td>{{ difs.pr }}</td>                 <--- should be dif.pr
    </tr>
{% endfor %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM