# 基于類的通用視圖 —— 索引 #
這里的索引提供基于類的視圖的另外一種組織形式。對于每個視圖,在類繼承樹中有效的屬性和方法都顯示在該視圖的下方。按照行為進行組織的文檔,參見基于類的視圖。
## 簡單的通用視圖 ##
### View ###
`class View`
屬性 (以及訪問它們的方法):
+ `http_method_names`
方法
+ `as_view()`
+ `dispatch()`
+ `head()`
+ `http_method_not_allowed()`
### TemplateView ###
`class TemplateView`
屬性 (以及訪問它們的方法):
+ `content_type`
+ `http_method_names`
+ `response_class` [`render_to_response()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `head()`
+ `http_method_not_allowed()`
+ `render_to_response()`
### RedirectView ###
`class RedirectView`
屬性 (以及訪問它們的方法):
+ `http_method_names`
+ `pattern_name`
+ `permanent`
+ `query_string`
+ `url` [`get_redirect_url()`]
方法
+ `as_view()`
+ `delete()`
+ `dispatch()`
+ `get()`
+ `head()`
+ `http_method_not_allowed()`
+ `options()`
+ `post()`
+ `put()`
## 明細視圖 ##
### DetailView ###
`class DetailView`
屬性 (以及訪問它們的方法):
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `http_method_names`
+ `model`
+ `pk_url_kwarg`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `slug_field` [`get_slug_field()`]
+ `slug_url_kwarg`
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_field`
+ `template_name_suffix`
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_object()`
+ `head()`
+ `http_method_not_allowed()`
+ `render_to_response()`
## 清單視圖 ##
### ListView ###
`class ListView`
屬性 (以及訪問它們的方法):
+ `allow_empty` [`get_allow_empty()`]
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `http_method_names`
+ `model`
+ `ordering` [`get_ordering()`]
+ `paginate_by` [`get_paginate_by()`]
+ `paginate_orphans` [`get_paginate_orphans()`]
+ `paginator_class`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_suffix`
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_paginator()`
+ `head()`
+ `http_method_not_allowed()`
+ `paginate_queryset()`
+ `render_to_response()`
## 編輯視圖 ##
### FormView ###
`class FormView`
屬性 (以及訪問它們的方法):
+ `content_type`
+ `form_class` [`get_form_class()`]
+ `http_method_names`
+ `initial` [`get_initial()`]
+ `prefix` [`get_prefix()`]
+ `response_class` [`render_to_response()`]
+ `success_url` [`get_success_url()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
方法
+ `as_view()`
+ `dispatch()`
+ `form_invalid()`
+ `form_valid()`
+ `get()`
+ `get_context_data()`
+ `get_form()`
+ `get_form_kwargs()`
+ `http_method_not_allowed()`
+ `post()`
+ `put()`
### CreateView ###
`class CreateView`
屬性 (以及訪問它們的方法):
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `fields`
+ `form_class` [`get_form_class()`]
+ `http_method_names`
+ `initial` [`get_initial()`]
+ `model`
+ `pk_url_kwarg`
+ `prefix` [`get_prefix()`]
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `slug_field` [`get_slug_field()`]
+ `slug_url_kwarg`
+ `success_url` [`get_success_url()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_field`
+ `template_name_suffix`
方法
+ `as_view()`
+ `dispatch()`
+ `form_invalid()`
+ `form_valid()`
+ `get()`
+ `get_context_data()`
+ `get_form()`
+ `get_form_kwargs()`
+ `get_object()`
+ `head()`
+ `http_method_not_allowed()`
+ `post()`
+ `put()`
+ `render_to_response()`
### UpdateView ###
`class UpdateView`
屬性 (以及訪問它們的方法):
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `fields`
+ `form_class` [`get_form_class()`]
+ `http_method_names`
+ `initial` [`get_initial()`]
+ `model`
+ `pk_url_kwarg`
+ `prefix` [`get_prefix()`]
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `slug_field` [`get_slug_field()`]
+ `slug_url_kwarg`
+ `success_url` [`get_success_url()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_field`
+ `template_name_suffix`
方法
+ `as_view()`
+ `dispatch()`
+ `form_invalid()`
+ `form_valid()`
+ `get()`
+ `get_context_data()`
+ `get_form()`
+ `get_form_kwargs()`
+ `get_object()`
+ `head()`
+ `http_method_not_allowed()`
+ `post()`
+ `put()`
+ `render_to_response()`
### DeleteView ###
`class DeleteView`
屬性 (以及訪問它們的方法):
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `http_method_names`
+ `model`
+ `pk_url_kwarg`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `slug_field` [`get_slug_field()`]
+ `slug_url_kwarg`
+ `success_url` [`get_success_url()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_field`
+ `template_name_suffix`
方法
+ `as_view()`
+ `delete()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_object()`
+ `head()`
+ `http_method_not_allowed()`
+ `post()`
+ `render_to_response()`
## 基于日期的視圖 ##
### ArchiveIndexView ###
`class ArchiveIndexView`
屬性 (以及訪問它們的方法):
+ `allow_empty` [`get_allow_empty()`]
+ `allow_future` [`get_allow_future()`]
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `date_field` [`get_date_field()`]
+ `http_method_names`
+ `model`
+ `ordering` [`get_ordering()`]
+ `paginate_by` [`get_paginate_by()`]
+ `paginate_orphans` [`get_paginate_orphans()`]
+ `paginator_class`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_suffix`
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_date_list()`
+ `get_dated_items()`
+ `get_dated_queryset()`
+ `get_paginator()`
+ `head()`
+ `http_method_not_allowed()`
+ `paginate_queryset()`
+ `render_to_response()`
### YearArchiveView ###
`class YearArchiveView`
屬性 (以及訪問它們的方法):
+ `allow_empty` [`get_allow_empty()`]
+ `allow_future` [`get_allow_future()`]
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `date_field` [`get_date_field()`]
+ `http_method_names`
+ `make_object_list` [`get_make_object_list()`]
+ `model`
+ `ordering` [`get_ordering()`]
+ `paginate_by` [`get_paginate_by()`]
+ `paginate_orphans` [`get_paginate_orphans()`]
+ `paginator_class`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_suffix`
+ `year` [`get_year()`]
+ `year_format` [`get_year_format()`]
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_date_list()`
+ `get_dated_items()`
+ `get_dated_queryset()`
+ `get_paginator()`
+ `head()`
+ `http_method_not_allowed()`
+ `paginate_queryset()`
+ `render_to_response()`
### MonthArchiveView ###
`class MonthArchiveView`
屬性 (以及訪問它們的方法):
+ `allow_empty` [`get_allow_empty()`]
+ `allow_future` [`get_allow_future()`]
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `date_field` [`get_date_field()`]
+ `http_method_names`
+ `model`
+ `month` [`get_month()`]
+ `month_format` [`get_month_format()`]
+ `ordering` [`get_ordering()`]
+ `paginate_by` [`get_paginate_by()`]
+ `paginate_orphans` [`get_paginate_orphans()`]
+ `paginator_class`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_suffix`
+ `year` [`get_year()`]
+ `year_format` [`get_year_format()`]
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_date_list()`
+ `get_dated_items()`
+ `get_dated_queryset()`
+ `get_next_month()`
+ `get_paginator()`
+ `get_previous_month()`
+ `head()`
+ `http_method_not_allowed()`
+ `paginate_queryset()`
+ `render_to_response()`
### WeekArchiveView ###
`class WeekArchiveView`
屬性 (以及訪問它們的方法):
+ `allow_empty` [`get_allow_empty()`]
+ `allow_future` [`get_allow_future()`]
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `date_field` [`get_date_field()`]
+ `http_method_names`
+ `model`
+ `ordering` [`get_ordering()`]
+ `paginate_by` [`get_paginate_by()`]
+ `paginate_orphans` [`get_paginate_orphans()`]
+ `paginator_class`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_suffix`
+ `week` [`get_week()`]
+ `week_format` [`get_week_format()`]
+ `year` [`get_year()`]
+ `year_format` [`get_year_format()`]
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_date_list()`
+ `get_dated_items()`
+ `get_dated_queryset()`
+ `get_paginator()`
+ `head()`
+ `http_method_not_allowed()`
+ `paginate_queryset()`
+ `render_to_response()`
### DayArchiveView ###
`class DayArchiveView`
屬性 (以及訪問它們的方法):
+ `allow_empty` [`get_allow_empty()`]
+ `allow_future` [`get_allow_future()`]
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `date_field` [`get_date_field()`]
+ `day` [`get_day()`]
+ `day_format` [`get_day_format()`]
+ `http_method_names`
+ `model`
+ `month` [`get_month()`]
+ `month_format` [`get_month_format()`]
+ `ordering` [`get_ordering()`]
+ `paginate_by` [`get_paginate_by()`]
+ `paginate_orphans` [`get_paginate_orphans()`]
+ `paginator_class`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_suffix`
+ `year` [`get_year()`]
+ `year_format` [`get_year_format()`]
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_date_list()`
+ `get_dated_items()`
+ `get_dated_queryset()`
+ `get_next_day()`
+ `get_next_month()`
+ `get_paginator()`
+ `get_previous_day()`
+ `get_previous_month()`
+ `head()`
+ `http_method_not_allowed()`
+ `paginate_queryset()`
+ `render_to_response()`
### TodayArchiveView ###
`class TodayArchiveView`
屬性 (以及訪問它們的方法):
+ `allow_empty` [`get_allow_empty()`]
+ `allow_future` [`get_allow_future()`]
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `date_field` [`get_date_field()`]
+ `day` [`get_day()`]
+ `day_format` [`get_day_format()`]
+ `http_method_names`
+ `model`
+ `month` [`get_month()`]
+ `month_format` [`get_month_format()`]
+ `ordering` [`get_ordering()`]
+ `paginate_by` [`get_paginate_by()`]
+ `paginate_orphans` [`get_paginate_orphans()`]
+ `paginator_class`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_suffix`
+ `year` [`get_year()`]
+ `year_format` [`get_year_format()`]
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_date_list()`
+ `get_dated_items()`
+ `get_dated_queryset()`
+ `get_next_day()`
+ `get_next_month()`
+ `get_paginator()`
+ `get_previous_day()`
+ `get_previous_month()`
+ `head()`
+ `http_method_not_allowed()`
+ `paginate_queryset()`
+ `render_to_response()`
### DateDetailView ###
`class DateDetailView`
屬性 (以及訪問它們的方法):
+ `allow_future` [`get_allow_future()`]
+ `content_type`
+ `context_object_name` [`get_context_object_name()`]
+ `date_field` [`get_date_field()`]
+ `day` [`get_day()`]
+ `day_format` [`get_day_format()`]
+ `http_method_names`
+ `model`
+ `month` [`get_month()`]
+ `month_format` [`get_month_format()`]
+ `pk_url_kwarg`
+ `queryset` [`get_queryset()`]
+ `response_class` [`render_to_response()`]
+ `slug_field` [`get_slug_field()`]
+ `slug_url_kwarg`
+ `template_engine`
+ `template_name` [`get_template_names()`]
+ `template_name_field`
+ `template_name_suffix`
+ `year` [`get_year()`]
+ `year_format` [`get_year_format()`]
方法
+ `as_view()`
+ `dispatch()`
+ `get()`
+ `get_context_data()`
+ `get_next_day()`
+ `get_next_month()`
+ `get_object()`
+ `get_previous_day()`
+ `get_previous_month()`
+ `head()`
+ `http_method_not_allowed()`
+ `render_to_response()`
> 譯者:[Django 文檔協作翻譯小組](http://python.usyiyi.cn/django/index.html),原文:[Flattened index](https://docs.djangoproject.com/en/1.8/ref/class-based-views/flattened-index/)。
>
> 本文以 [CC BY-NC-SA 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/cn/) 協議發布,轉載請保留作者署名和文章出處。
>
> [Django 文檔協作翻譯小組](http://python.usyiyi.cn/django/index.html)人手緊缺,有興趣的朋友可以加入我們,完全公益性質。交流群:467338606。
- 新手入門
- 從零開始
- 概覽
- 安裝
- 教程
- 第1部分:模型
- 第2部分:管理站點
- 第3部分:視圖和模板
- 第4部分:表單和通用視圖
- 第5部分:測試
- 第6部分:靜態文件
- 高級教程
- 如何編寫可重用的應用
- 為Django編寫首個補丁
- 模型層
- 模型
- 模型語法
- 元選項
- 模型類
- 查詢集
- 執行查詢
- 查找表達式
- 模型的實例
- 實例方法
- 訪問關聯對象
- 遷移
- 模式編輯器
- 編寫遷移
- 高級
- 管理器
- 原始的SQL查詢
- 聚合
- 多數據庫
- 自定義查找
- 條件表達式
- 數據庫函數
- 其它
- 遺留的數據庫
- 提供初始數據
- 優化數據庫訪問
- 視圖層
- 基礎
- URL配置
- 視圖函數
- 快捷函數
- 裝飾器
- 參考
- 內建的視圖
- TemplateResponse 對象
- 文件上傳
- 概覽
- File 對象
- 儲存API
- 管理文件
- 自定義存儲
- 基于類的視圖
- 概覽
- 內建顯示視圖
- 內建編輯視圖
- API參考
- 分類索引
- 高級
- 生成 CSV
- 生成 PDF
- 中間件
- 概覽
- 內建的中間件類
- 模板層
- 基礎
- 面向設計師
- 語言概覽
- 人性化
- 面向程序員
- 表單
- 基礎
- 概覽
- 表單API
- 內建的Widget
- 高級
- 整合媒體
- 開發過程
- 設置
- 概覽
- 應用程序
- 異常
- 概覽
- django-admin 和 manage.py
- 添加自定義的命令
- 測試
- 介紹
- 部署
- 概述
- WSGI服務器
- 部署靜態文件
- 通過email追蹤代碼錯誤
- Admin
- 管理操作
- 管理文檔生成器
- 安全
- 安全概述
- 說明Django中的安全問題
- 點擊劫持保護
- 加密簽名
- 國際化和本地化
- 概述
- 本地化WEB UI格式化輸入
- “本地特色”
- 常見的網站應用工具
- 認證
- 概覽
- 使用認證系統
- 密碼管理
- 日志
- 分頁
- 會話
- 數據驗證
- 其它核心功能
- 按需內容處理
- 重定向
- 信號
- 系統檢查框架