zoukankan      html  css  js  c++  java
  • Django Generic View 之 archive_year

    开发网络应用程序有时是单调乏味的,因为我们对于某些操作(或者模式)重复来重复去,重复的事情做的多了也就觉得乏味了。在Django中,这类常见的操作都已经被抽象为Generic Views(通用视图)。借用Generic Views,我们不用写一行python代码就可以提供一些常见的view操作。比如:

    django.views.generic.date_based.archive_year
    django.views.generic.date_based.archive_month
    django.views.generic.date_based.archive_week
    django.views.generic.date_based.archive_day
    django.views.generic.date_based.archive_today
    django.views.generic.date_based.object_detail
    等等。

    在这类Generic Views中archive_year显得有点儿特殊,因为其中有一个其他Generic Views中所没有的参数make_object_list,按照Django的官方说法,当make_object_list为True时,会将该年中的所有相关记录组成一个list传递到对应的template中,list名字由template_object_name + "_list"指定(默认为object_list);如果make_object_list为False,传入template中的list将为空,为不管实际中有多少条相关记录。很奇怪,不知道Django为何采用这种策略。所以使用archive_year通用视图时要特别注意make_object_list的值。

  • 相关阅读:
    指示函数
    Sql Server中的日期与时间函数
    http://www.jb51.net/softjc/33896.html(vs2010破解)
    什么是VC维?
    smalldatetime和datetime的差别
    基于大规模语料的新词发现算法
    向setInterval , setTimeout调用的函数传递参数
    取指定月份的天数
    SQL 写循环数据
    JavaScript事件一瞥
  • 原文地址:https://www.cnblogs.com/Jerryshome/p/1783180.html
Copyright © 2011-2022 走看看