Originating From: http://blog.csdn.net/dbanote/article/details/11338953
Before I formally started coding, I felt it necessary to explore the Django model of MTV, combining theory with practice to get a better grasp of the technology. First of all, the famous MVC pattern in Web server development, so-called MVC is to divide the Web application into models (M), Controller (C) and view (V) layer three, they are connected in a plug-in, loosely coupled way, the model is responsible for the business object and database Mapping (ORM), The view is responsible for interacting with the user (page), the controller accepts the user's input to call the model and the view completes the user's request, as follows: The Django MTV model is essentially the same as MVC, and it's just a little different from the definition to keep the coupling between the components. The Django MTV is the value:
M stands for model:A relational mapping (ORM) that is responsible for business objects and databases.
T stands for Template:Responsible for how to display the page to the user (HTML).
V for Views (view): Responsible for business logic, and call model and template at the appropriate time. In addition to the above three layers, a URL dispatcher is needed to distribute the page requests for each URL to different view processes, and the response pattern for the view to call the corresponding model and TEMPLATE,MTV is as follows: 1, Web server (middleware) receives an HTTP request
2,django find the corresponding view function in urlconf to handle the HTTP request
3, the view function calls the corresponding data model to access the data, invokes the corresponding template to show the page to the user
4, the View function returns an HTTP response to the Web server after processing ends
The 5,web server sends the response to the client the key advantage of this design pattern is that the various components are loosely coupled. Thus, each Django-driven Web application has a clear purpose and can be changed independently without affecting other parts.
For example, a developer changes a URL in an application without affecting the underlying implementation of the program. Designers can change the style of the HTML page without touching the Python code.
The database administrator can rename the data tables and simply change the model without needing to find and replace them from a large stack of files. To be implemented, the Python file for the Django MTV model is as follows:
Django MTV Mode Learning