-
每月存档页面,显示给定月份中的所有对象。除非您将
allow_future
设置为True
,否则不会显示日期在future
中的对象。祖先 (MRO)
django.views.generic.list.MultipleObjectTemplateResponseMixin
django.views.generic.base.TemplateResponseMixin
django.views.generic.dates.BaseMonthArchiveView
django.views.generic.dates.YearMixin
django.views.generic.dates.MonthMixin
django.views.generic.dates.BaseDateListView
- MultipleObjectMixin
django.views.generic.dates.DateMixin
- View
语境
除了
MultipleObjectMixin
BaseDateListView
date_list
:一个QuerySet
queryset
,表示为datetime.datetime
month
:表示给定月份的date
next_month
:根据allow_empty
allow_future
date
previous_month
:根据allow_empty
allow_future
date
注意
- 使用
_archive_month
的默认template_name_suffix
。
示例 myapp/views.py:
from django.views.generic.dates import MonthArchiveView from myapp.models import Article class ArticleMonthArchiveView(MonthArchiveView): queryset = Article.objects.all() date_field = "pub_date" allow_future = True
示例 myapp/urls.py:
from django.urls import path from myapp.views import ArticleMonthArchiveView urlpatterns = [ # Example: /2012/08/ path('<int:year>/<int:month>/', ArticleMonthArchiveView.as_view(month_format='%m'), name="archive_month_numeric"), # Example: /2012/aug/ path('<int:year>/<str:month>/', ArticleMonthArchiveView.as_view(), name="archive_month"), ]
示例 myapp/article_archive_month.html:
<ul> {% for article in object_list %} <li>{{ article.pub_date|date:"F j, Y" }}: {{ article.title }}</li> {% endfor %} </ul> <p> {% if previous_month %} Previous Month: {{ previous_month|date:"F Y" }} {% endif %} {% if next_month %} Next Month: {{ next_month|date:"F Y" }} {% endif %} </p>
本文介绍 django.views.generic.dates.MonthArchiveView
的用法。
声明
class MonthArchiveView
相关用法
- Python Django ModelAdmin.get_changeform_initial_data用法及代码示例
- Python Django ModelAdmin.get_formset_kwargs用法及代码示例
- Python Django ModelAdmin.get_urls用法及代码示例
- Python Django ModelAdmin.formfield_for_choice_field用法及代码示例
- Python Django ModelAdmin.readonly_fields用法及代码示例
- Python Django Model.from_db用法及代码示例
- Python Django ModelAdmin.prepopulated_fields用法及代码示例
- Python Django ModelAdmin.empty_value_display用法及代码示例
- Python Django ModelAdmin.get_form用法及代码示例
- Python Django ModelChoiceField.iterator用法及代码示例
- Python Django ModelAdmin.formfield_for_foreignkey用法及代码示例
- Python Django ModelAdmin.get_search_results用法及代码示例
- Python Django ModelAdmin.autocomplete_fields用法及代码示例
- Python Django ModelAdmin.date_hierarchy用法及代码示例
- Python Django ModelAdmin.get_formsets_with_inlines用法及代码示例
- Python Django ModelAdmin.save_model用法及代码示例
- Python Django ModelAdmin.view_on_site用法及代码示例
- Python Django ModelChoiceField.empty_label用法及代码示例
- Python Django Model.__eq__用法及代码示例
- Python Django ModelAdmin.get_inline_instances用法及代码示例
- Python Django ModelAdmin.formfield_overrides用法及代码示例
- Python Django ModelAdmin.get_changelist_formset用法及代码示例
- Python Django Model.__str__用法及代码示例
- Python Django ModelAdmin.get_sortable_by用法及代码示例
- Python Django ModelAdmin.fields用法及代码示例
注:本文由纯净天空筛选整理自djangoproject.com大神的英文原创作品 django.views.generic.dates.MonthArchiveView。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。