Accessing a dict by variable in Django templates?

前端 未结 4 1081
忘掉有多难
忘掉有多难 2020-12-09 08:31

My view code looks basically like this:

context = Context() 
context[\'my_dict\'] = {\'a\': 4, \'b\': 8, \'c\': 15, \'d\': 16, \'e\': 23, \'f\': 42 }
context         


        
4条回答
  •  温柔的废话
    2020-12-09 09:00

    Try this to display the keys and values of the dictionary:

    {% for key, value in your_dict.items %}
        {{ key }}: {{ value }}
    {% endfor %}
    

    https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

提交回复
热议问题