Urlconf + MTV: MVC (zz) in Django eyes)

Source: Internet
Author: User

MVC is a well-known model, that is, applyingProgramIt is divided into three components: model, view, and controller ). Where:
M manages the state of the application (usually stored in the database) and limits the behavior of changing the State (or "Business Rules ").
C receives operations from external users, obtains data based on the Operation access model, and calls "View" to display the data. The Controller isolates the "model" and "View" and serves as a link between the two.
V is responsible for formatting the data and presenting it to the user.

In agile web development with rails, the following figure provides a good explanation of the MVC mode:

 

Django is also an MVC framework. However, in Django, the Framework processes the part that the controller accepts user input. Therefore, Django focuses more on models, templates, and views ), called the MTV mode:

M represents the model, that is, the data access layer. This layer processes all data-related transactions: how to access, how to Verify validity, What behaviors are included, and the relationship between data.

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

V represents the view, 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.

Note that the Django view cannot be regarded as an MVC controller and the Django template as an MVC view.
The difference is:
The Django view does not process user input, but only determines the data to be presented to users;
The Django template only determines how to display the specified data in the Django view.

In other words, Django further splits the view in MVC into two parts: the Django view and the Django template, which determine "what data to display" and "how to display", respectively ", this allows Django templates to be replaced at any time as needed, rather than built-in templates.

 

The MVC controller is implemented by urlconf of the Django framework. Urlconf is well designed. Its Mechanism is to use regular expressions to match URLs and then call appropriate Python functions. Although you are not used to it at the beginning, you will soon like it, because urlconf has no restrictions on URL rules, and you can design it into any URL style, whether it is traditional, restful or alternative.

Reposted from: urlconf + MTV: MVC in Django eyes

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.