2014-02-25 136 views
0

我有可能由下列值字典在Django模板

images={'25/02/2014': {u'Observation': [<Image: Image object>]}} 

{ 
    date:{title1:[obj1, obj2, obj3], title2:[obj1, obj2, obj3]}, 
    date2:{title1:[obj1, obj2, obj3]}, 
} 

的字典,我想單獨和最終訪問值爲每個標題的對象列表。我的代碼是

{%for date in images%} 
    {%for title in images.date%} #equivalent to for title in images[date]: 
     {{date}} - {{title}} 
     {% for obj in images.date.title%} #equivalent to for obj in images[date][title]: but not sure 
      {{obj}} 
     {%endfor%} 
    {%endfor%} 
{%endfor%} 

但它不起作用。它適用於dictionalry的python,但不適用於django模板。我怎樣才能訪問字典?

+0

http://goo.gl/Evves1發現在這裏......請close..Sorry! – Apostolos

回答

1

你想重複的(鍵,值)對,而不是:

{% for date, data in images.items %} 
    {% for title, images in data.items %} 
    {{date}} - {{title}} 
    {% for image in images %} 
     {{ image }} 
    {% endfor %} 
    {% endfor %} 
{% endfor %} 
+0

是的,謝謝。按照原樣工作 – Apostolos