[Fixed]-Passing data through render to template

1👍

news_list[monthyear] = {'Year': year, 'Month' : month}

The datastructure returned by build_news_archive is an object. When iterating over an object in python (and django templates) the keys are iterated over by default

 <ol class="list-unstyled">
  {% for monthyear, archive in newsarchive.items %}
    <li>{{ archive.year }} + {{ archive.month }}</li>
  {% endfor %}
  </ol>

you can call python items dict method in django template by accessing your_dict.items in a for loop
https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#for

0👍

What happens when you try to do this? The one thing I noticed is that you are referring to the dictionary keys ‘Year’ and ‘Month’ as ‘year’ and ‘month’ (noticed the difference in case of the first letter). The template is processed on the server side and hence should be case-sensitive.
Other than that, dm03514’s suggestion is should be incorporated as well.

👤Sid

0👍

Try this might help

return render(request, 'en/public/news.html', locals())

<ol class="list-unstyled">
  {% for archive in rDict.newsarchive %}
    <li>{{ archive.year }} + {{ archive.month }}</li>
  {% endfor %}
  </ol>
👤chandu

Leave a comment