当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Django templates json loops

问题描述:

I use python/django views to get an output as:

{{ test }}

in my template. Here is the output

{'platform': 'xbox', 'amount': '50.00', 'title': 'title of something', 'description': 'description of something'}

If I use

{% for x in test %}

{{ x }}

{% endfor %}

it outputs

platform, amount, title, description

How do I get the values and not the keys?

网友答案:

This is just standard Python iteration over a dictionary, which defaults to iterating over the keys. If you want just the values, use {% for x in test.values %}. If you want key/value pairs, use {% for k, v in test.items %}.

分享给朋友:
您可能感兴趣的文章:
随机阅读: