Django-class-based view source code analysis 1

Source: Internet
Author: User

Class-based view is a new view writing method introduced by Django 1.3. It is used to replace the previous function-based view writing method.
With the convenience of multiple inheritance features in OO and python, class-based views can provide better abstraction and reuse capabilities. The new general view will be more elegant.

Django has many documents, but it is often not enough in actual development. In many cases, you still need to go deep into the source code. To this end, we carefully reviewed the implementation of class-based views. We hope to provide a clearer and direct reference for future development.

Description: Django applies multiple inheritance features in a large number. To split some common functional code into a class (Mixin), you only need to add the mixed class to the class inheritance list when you need the code that is mixed into the class-pay attention to the order, the class on the left has higher permissions and will overwrite the functions with the same name in the inherited class on the right. For ease of instruction, you can turn these mixed classes (Mixin) into "tool classes ".

Source Code Organization

All view-related code is stored in the directory Django/views/generic:

  • Base. py: the abstract class for saving views, templateview and redirectview, and the Code for templateresponsemixin.

  • Create_update.py is a function-based general view. MarkedDeprecated

  • Date_based.py is a function-based date-related general view. MarkedDeprecated

  • Dates. py is a new generic class-based date view. Used to replace date_based.py

  • Detail. py displays related views and tool classes for a single object based on the class

  • Edit. py: class-based object editing related views and tool classes

  • List. py displays related views and tool classes based on the class Object List

  • List_detail.py is a function-based list and display function. MarkedDeprecated

  • Simply. py is a common function-based tool. MarkedDeprecated

Logically, the source code is organized into abstract base classes, tool classes (Mixin), conventional (specific) implementations, and model-based implementations.

Django-class-based view source code analysis 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.