- 
按日期顯示 “latest” 對象的頂級索引頁麵。除非您將
allow_future設置為True,否則不包括日期在future中的對象。祖先 (MRO)
django.views.generic.list.MultipleObjectTemplateResponseMixindjango.views.generic.base.TemplateResponseMixindjango.views.generic.dates.BaseArchiveIndexViewdjango.views.generic.dates.BaseDateListView- MultipleObjectMixin
 django.views.generic.dates.DateMixin- View
 
語境
除了
(通過django.views.generic.list.MultipleObjectMixin)提供的上下文之外,模板的上下文將是:django.views.generic.dates.BaseDateListViewdate_list:一個對象,包含根據QuerySetqueryset具有可用對象的所有年份,表示為對象,按降序排列。datetime.datetime
注意
- 使用 
latest的默認context_object_name。 - 使用 
_archive的默認template_name_suffix。 - 默認按年提供 
date_list,但可以使用屬性date_list_period將其更改為月或日。這也適用於所有子類視圖。 
示例 myapp/urls.py:
from django.urls import path from django.views.generic.dates import ArchiveIndexView from myapp.models import Article urlpatterns = [ path('archive/', ArchiveIndexView.as_view(model=Article, date_field="pub_date"), name="article_archive"), ]示例 myapp/article_archive.html:
<ul> {% for article in latest %} <li>{{ article.pub_date }}: {{ article.title }}</li> {% endfor %} </ul>這將輸出所有文章。
 
本文介紹 django.views.generic.dates.ArchiveIndexView 的用法。
聲明
class ArchiveIndexView
相關用法
- Python Django Area用法及代碼示例
 - Python Django ArraySubquery用法及代碼示例
 - Python Django Area.__getattr__用法及代碼示例
 - Python Django Area.unit_attname用法及代碼示例
 - Python Django ArrayAgg.ordering用法及代碼示例
 - Python Django ArrayField.base_field用法及代碼示例
 - Python Tweepy API.mentions_timeline()用法及代碼示例
 - Python Tweepy API.get_user()用法及代碼示例
 - Python Tweepy API.list_timeline()用法及代碼示例
 - Python Django ACos用法及代碼示例
 - Python Tweepy API.add_list_members()用法及代碼示例
 - Python Django Abs用法及代碼示例
 - Python Django AuthenticationForm.confirm_login_allowed用法及代碼示例
 - Python Tweepy API.create_block()用法及代碼示例
 - Python Django ATan用法及代碼示例
 - Python Tweepy API.trends_closest()用法及代碼示例
 - Python Tweepy API.send_direct_message()用法及代碼示例
 - Python Tweepy API.destroy_status()用法及代碼示例
 - Python Tweepy API.destroy_saved_search()用法及代碼示例
 - Python Tweepy API.get_list()用法及代碼示例
 - Python Tweepy API.favorites()用法及代碼示例
 - Python Tweepy API.blocks_ids()用法及代碼示例
 - Python Tweepy API.configuration()用法及代碼示例
 - Python Tweepy API.lists_memberships()用法及代碼示例
 - Python Tweepy API.home_timeline()用法及代碼示例
 
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.views.generic.dates.ArchiveIndexView。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
