Python django-在templatetag中显示OrderedDict

Python django-在templatetag中显示OrderedDict,python,django,django-templates,ordereddictionary,templatetags,Python,Django,Django Templates,Ordereddictionary,Templatetags,我有一个订购的dict,我需要显示它的键,值,但我无法获得它的值,我有这个dict=([('sainbath','thesailor'),('HELLO','WORLD')),我试过这个 {{object.specifications}} <ul> <li>{% for key in object.specifications %} {{key}} {%endfor%} {{object.specifi

我有一个订购的dict,我需要显示它的键,值,但我无法获得它的值,我有这个dict=([('sainbath','thesailor'),('HELLO','WORLD')),我试过这个

{{object.specifications}}
      <ul>
        <li>{% for key in object.specifications %}
          {{key}}
          {%endfor%}
{{object.specifications}
  • {object.specifications%中的键为%s} {{key}} {%endfor%}
我得到这个输出

订购信息([('sainbath','thesailor'),('HELLO','WORLD'))

  • 赛恩巴斯你好
当我尝试这个时,我得到的只是它的键而不是它的值

{{object.specifications}}
      <ul>
        <li>{% for key,value in object.specifications %}
          {{key}} : {{value}}
          {%endfor%}
{{object.specifications}
  • {%表示键,值在object.specifications%} {{key}}:{{value} {%endfor%}
这给了我错误

需要2个值才能在for循环中解包;得了8分。 请告诉我如何才能获得价值

1) 在模板中使用以下内容:

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

2) 如果要将数据作为OrderedDict呈现模板,可以使用以下方法进行相同的呈现

return render_to_response('your_template.html',{'data': sorted(your_ordered_dict.iteritems())})
在模板中,您可以使用与以下相同的内容:

{% for key, value in data %}
     {{key}}:{{value}}
{% endfor %}
希望它能帮助你