class ArchiveIndexView [source]
A top-level index page showing the “latest” objects, by date. Objects with a date in the future are not included unless you set allow_future to True.
Ancestors (MRO)
django.views.generic.list.MultipleObjectTemplateResponseMixindjango.views.generic.base.TemplateResponseMixindjango.views.generic.dates.BaseArchiveIndexViewdjango.views.generic.dates.BaseDateListViewdjango.views.generic.list.MultipleObjectMixindjango.views.generic.dates.DateMixindjango.views.generic.base.View
Context
In addition to the context provided by django.views.generic.list.MultipleObjectMixin (via django.views.generic.dates.BaseDateListView), the template’s context will be:
-
date_list: AQuerySetobject containing all years that have objects available according toqueryset, represented asdatetime.datetimeobjects, in descending order.
Notes
- Uses a default
context_object_nameoflatest. - Uses a default
template_name_suffixof_archive. - Defaults to providing
date_listby year, but this can be altered to month or day using the attributedate_list_period. This also applies to all subclass views.
Example myapp/urls.py:
from django.conf.urls import url
from django.views.generic.dates import ArchiveIndexView
from myapp.models import Article
urlpatterns = [
url(r'^archive/$',
ArchiveIndexView.as_view(model=Article, date_field="pub_date"),
name="article_archive"),
]
Example myapp/article_archive.html:
<ul>
{% for article in latest %}
<li>{{ article.pub_date }}: {{ article.title }}</li>
{% endfor %}
</ul>
This will output all articles.
Please login to continue.