title: How to iterate over nested dictionaries in django templates
body: <p>I'm not sure the most efficient way to iterate over my nested dictionaries to print a matrix of the total and good values for every fruit for each date.  Take for instance the two lists and dictionary below:</p>
  
  <pre><code>fruits = ['apples','oranges','bananas']
  harvest_dates = ['2011-07-23','2011-07-22','2011-07-21']
  
  harvest_data = {
    'apples': {
      '2011-07-23': {
        'total': 100,
        'good': 80},
       '2011-07-22': {
         'total': 97,
         'good': 92},
       '2011-07-21': {
         'total': 90,
         'good': 85}
    },
    'oranges': {
      '2011-07-23': {
        'total': 86,
        'good': 82},
      '2011-07-22': {
        'total': 90, 
        'good': 75},
      '2011-07-21': {
        'total': 92,
        'good': 92}
    },
    'bananas': {
      '2011-07-23': {
        'total': 10,
        'good': 9},
      '2011-07-22': {
        'total': 12, 
        'good': 11},
      '2011-07-21': {
        'total': 9,
        'good': 9}
    }
  }
  </code></pre>
  
  <p>I can easily do this in python:</p>
  
  <pre><code>for fruit in fruits:
    for day in harvest_dates:
      print "harvest: %s" % harvest_data[fruit][day]['total']
      print "good crop: %s" % harvest_data[fruit][day]['good']
  </code></pre>
  
  <p>But I don't know how to access this data in django templates.  I had been trying something such as:</p>
  
  <pre><code>{% for fruit in fruits %}
    ...
    {% for day in harvest_dates %}
      ...
      {{ harvest_data.fruit.day.total }}
      {{ harvest_data.fruit.day.good }}
      ...
    {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>But it's simply not working.</p>
  
  <pre><code>{% for fruit in fruits %}
    {{ harvest_data.fruit }}  &lt;--- this does not exist
    {{ harvest_data[fruit] }}  &lt;--- this does not work
  {% endfor %}
  </code></pre>
  
  <p>I'm a complete amateur and I'm probably going about this all wrong, but I've Google'd quite a bit and it's not clear to me what the best approach to getting the data I want is.</p>