Django MTV Development Model
Category:
Python
Read by 462
Comment (0)
Favorites
Report the MTV Development Model
Before studying more code, let's take a moment to consider the overall design of Django data-driven Web applications.
As we mentioned earlier, Django
The design encourages loose coupling and strict segmentation of different parts of the application. To follow this idea, it is easier to modify a part of the application without affecting other parts. In view functions, we have discussed
The importance of separating the business logic from the presentation logic through the template system. At the database layer, we also applied the same idea to the data access logic.
The concept of combining data access logic, business logic, and performance logic is sometimes called a Software ArchitectureModel-View-Controller(MVC) mode. In this mode, the model represents the data access layer, and the view represents what and how to display in the system, controller refers to the part of the system that accesses the model based on user input and as needed to determine which view to use.
Why is it abbreviated?
A clearly defined pattern like MVC is mainly used to improve communication between developers. Instead of telling our colleagues: "Let's abstract data access, use a separate layer to display data, and place a layer in the middle for control", it's better to use common words to tell them: "Let's use the MVC mode here ".
Django closely follows this MVC pattern, which can be called an MVC framework. The meanings of M, V, and C in Django are as follows:
Since C is processed by the framework itself, Django is more concerned with model, template, and views. Django is also calledMTV framework. In the MTV Development Mode:
MModel, that is, the data access layer. This layer processes all data-related transactions: how to access, how to validate, What behaviors are included, and the relationship between data.
VView, that is, the business logic layer. This layer contains the access model and related logic for obtaining the appropriate template. You can think of it as a bridge between a model and a template.
If you are familiar with other MVC web development frameworks, such as Ruby on Rails, you may think
The Django view is the controller, while the Django template is the view. Unfortunately, this is a misunderstanding caused by different interpretations of MVC. In Django
The view is used to describe the data to be presented to the user.How about, But to presentWhichData. In contrast, Ruby on Rails and some similar frameworks advocate controllers to determine the data to be presented to users, while views only determineHowShow data, not showWhichData.
None of the two interpretations are more correct. It is important to understand the underlying concepts.