-
顯示給定日期的所有對象的日期存檔頁麵。未來幾天拋出 404 錯誤,無論未來幾天是否存在任何對象,除非您將
allow_future
設置為True
。祖先 (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
- MultipleObjectMixin
django.views.generic.dates.DateMixin
- View
語境
除了
MultipleObjectMixin
BaseDateListView
day
:表示給定日期的date
next_day
:根據allow_empty
allow_future
date
previous_day
:代表前一天的date
allow_empty
allow_future
next_month
:根據allow_empty
allow_future
date
previous_month
:根據allow_empty
allow_future
date
注意
- 使用
_archive_day
的默認template_name_suffix
。
示例 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
示例 myapp/urls.py:
from django.urls import path from myapp.views import ArticleDayArchiveView urlpatterns = [ # Example: /2012/nov/10/ path('<int:year>/<str:month>/<int:day>/', ArticleDayArchiveView.as_view(), name="archive_day"), ]
示例 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>
本文介紹 django.views.generic.dates.DayArchiveView
的用法。
聲明
class DayArchiveView
相關用法
- Python Django DataSource用法及代碼示例
- Python Datetime.replace()用法及代碼示例
- Python Django DateDetailView用法及代碼示例
- Python DateTime轉integer用法及代碼示例
- Python DataFrame.to_excel()用法及代碼示例
- Python Tableau DatasourceItem用法及代碼示例
- Python DateTime astimezone()用法及代碼示例
- Python DataFrame.read_pickle()用法及代碼示例
- Python Django DateTimeField.input_formats用法及代碼示例
- Python DateTime weekday()用法及代碼示例
- Python Pandas DataFrame.fillna()用法及代碼示例
- Python Decimal shift()用法及代碼示例
- Python Decimal rotate()用法及代碼示例
- Python Decimal max_mag()用法及代碼示例
- Python Decimal as_integer_ratio()用法及代碼示例
- Python Decimal is_subnormal()用法及代碼示例
- Python Decimal canonical()用法及代碼示例
- Python Decimal from_float()用法及代碼示例
- Python Decimal normalize()用法及代碼示例
- Python Decimal radix()用法及代碼示例
- Python Dictionary update()用法及代碼示例
- Python Decimal copy_abs()用法及代碼示例
- Python Decimal is_finite()用法及代碼示例
- Python Decimal conjugate()用法及代碼示例
- Python Django Distance用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.views.generic.dates.DayArchiveView。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。