사전

2014-02-25 3 views
0

나는사전

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

이며 다음 값

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

구성 할 수있는 사전을 가지고 있고 각각의 타이틀에 대해 개별적으로 결국 개체 목록을 값에 액세스 할 . 내 코드는

{%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%} 

이었지만 작동하지 않습니다. 그것은 python에서 dictionalry는 작동하지만 django template에서는 작동하지 않습니다. 사전에 어떻게 액세스 할 수 있습니까?

+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