I am using Django’s generic views to create a blog site. The
templates I created, entry_archive_day, entry_archive_month,
entry_archive, and entry_detail all work perfectly.
But entry_archive_year does not. Instead, it is simply a valid page with no content (not a 404 or other error. It looks like it sees no objects in **object_list**.
I know that archive uses a latest list instead of object_list,
but that’s not the case with archive_year, correct?
Thanks!
To solve your problem:
If you set
make_object_list=Truewhen callingarchive_year, then the list of objects for that year will be available asobject_list.As a quick example, if your url pattern looks like
where
info_dictis a dictionary containing thequerysetanddate_field, change it toExplanation:
The generic view
archive_yearhas an optional argumentmake_object_list. By default, it is set to false, andobject_listis passed to the template as an empty list.A reason for this is that you might not always want to display the entire object list in the
entry_archive_yearview. You may have hundreds of blog posts for that year, too many to display on one page.Instead,
archive_yearaddsdate_listto the template context. This allows you to create links to the monthly archive pages of that year, for the months which have entries.There’s more info in the Django docs.
As requested in the comment below, an example of how to use
date_list:To use
date_list, yourentry_archive_yeartemplate would contain something like this:Note that I’ve hardcoded the url – in practice it would be better to use the url template tag. For an example of
date_listbeing used in the wild, look at the Django Weblog 2009 Archive.