Go to: Django MTV Development Mode

Source: Internet
Author: User
Tags ruby on rails
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:

  • MThe data access part is processed by the Django database layer. This chapter describes the content.

  • VAnd select the data to be displayed and what to display, which are processed by the view and template.

  • CAccording to the part of the user input delegate view, the Django Framework calls an appropriate Python function from the line for processing the given URL by setting according to urlconf.

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.

  • TTemplate, that is, the presentation layer. This layer processes performance-related decisions: how to display them on pages or other types of documents.

  • 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.

Related Article

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.