Develop network applicationsProgramSometimes it is monotonous, because we repeat some operations (or modes), and it is boring to do more repetitive tasks. In Django, such common operations have been abstracted as generic views (general views ). Using generic views, we do not need to write a line of PythonCodeYou can provide some common view operations. For example:
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
And so on.
archive_year is special in this type of generic views, because make_object_list, which is not included in other generic views, according to Django's official statement, when make_object_list is true, A list of all related records in the year will be passed to the corresponding template, the list name is specified by template_object_name + "_ List" (object_list by default); if If make_object_list is false, the list in the input template is empty, regardless of the number of related records. It's strange that I don't know why Django adopts this policy. Therefore, when using the archive_year generic view, pay special attention to the value of make_object_list.