class DayArchiveView
[source]
A day archive page showing all objects in a given day. Days in the future throw a 404 error, regardless of whether any objects exist for future days, unless you set allow_future
to True
.
Ancestors (MRO)
django.views.generic.list.MultipleObjectTemplateResponseMixin
django.views.generic.base.TemplateResponseMixin
django.views.generic.dates.BaseDayArchiveView
django.views.generic.dates.YearMixin
django.views.generic.dates.MonthMixin
django.views.generic.dates.DayMixin
django.views.generic.dates.BaseDateListView
django.views.generic.list.MultipleObjectMixin
django.views.generic.dates.DateMixin
django.views.generic.base.View
Context
In addition to the context provided by MultipleObjectMixin
(via BaseDateListView
), the template’s context will be:
-
day
: Adate
object representing the given day. -
next_day
: Adate
object representing the next day, according toallow_empty
andallow_future
. -
previous_day
: Adate
object representing the previous day, according toallow_empty
andallow_future
. -
next_month
: Adate
object representing the first day of the next month, according toallow_empty
andallow_future
. -
previous_month
: Adate
object representing the first day of the previous month, according toallow_empty
andallow_future
.
Notes
- Uses a default
template_name_suffix
of_archive_day
.
Example myapp/views.py:
from django.views.generic.dates import DayArchiveView from myapp.models import Article class ArticleDayArchiveView(DayArchiveView): queryset = Article.objects.all() date_field = "pub_date" allow_future = True
Example myapp/urls.py:
from django.conf.urls import url from myapp.views import ArticleDayArchiveView urlpatterns = [ # Example: /2012/nov/10/ url(r'^(?P<year>[0-9]{4})/(?P<month>[-\w]+)/(?P<day>[0-9]+)/$', ArticleDayArchiveView.as_view(), name="archive_day"), ]
Example myapp/article_archive_day.html:
<h1>{{ day }}</h1> <ul> {% for article in object_list %} <li>{{ article.pub_date|date:"F j, Y" }}: {{ article.title }}</li> {% endfor %} </ul> <p> {% if previous_day %} Previous Day: {{ previous_day }} {% endif %} {% if previous_day and next_day %}--{% endif %} {% if next_day %} Next Day: {{ next_day }} {% endif %} </p>
Please login to continue.