-
顯示給定日期的所有對象的日期存檔頁麵。未來幾天拋出 404 錯誤,無論未來幾天是否存在任何對象,除非您將
allow_future設置為True。祖先 (MRO)
django.views.generic.list.MultipleObjectTemplateResponseMixindjango.views.generic.base.TemplateResponseMixindjango.views.generic.dates.BaseDayArchiveViewdjango.views.generic.dates.YearMixindjango.views.generic.dates.MonthMixindjango.views.generic.dates.DayMixindjango.views.generic.dates.BaseDateListView- MultipleObjectMixin
django.views.generic.dates.DateMixin- View
語境
除了
(通過MultipleObjectMixin)提供的上下文之外,模板的上下文將是:BaseDateListViewday:表示給定日期的對象。datenext_day:根據和allow_empty表示第二天的allow_future對象。dateprevious_day:代表前一天的對象,根據date和allow_empty。allow_futurenext_month:根據和allow_empty表示下個月第一天的allow_future對象。dateprevious_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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
