Django 简明教程
Django - Overview
正如您所知,Django 是一个 Python Web 框架。与大多数现代框架一样,Django 支持 MVC 模式。我们先来看看模型-视图-控制器 (MVC) 模式是什么,然后我们再来看看 Django 对模型-视图-模板 (MVT) 模式的特殊性。
As you already know, Django is a Python web framework. And like most modern framework, Django supports the MVC pattern. First let’s see what is the Model-View-Controller (MVC) pattern, and then we will look at Django’s specificity for the Model-View-Template (MVT) pattern.
MVC Pattern
当谈论提供 UI(Web 或桌面)的应用程序时,我们通常会讨论 MVC 架构。顾名思义,MVC 模式基于三个组件:模型、视图和控制器。{s2} 了解更多信息。
When talking about applications that provides UI (web or desktop), we usually talk about MVC architecture. And as the name suggests, MVC pattern is based on three components: Model, View, and Controller. Check our MVC tutorial here to know more.
DJANGO MVC - MVT Pattern
模型-视图-模板 (MVT) 与 MVC 稍有不同。事实上,这两种模式之间的主要区别在于 Django 本身负责控制器部分(控制模型和视图之间交互的软件代码),而我们保留了模板。模板是一个混合了 Django 模板语言 (DTL) 的 HTML 文件。
The Model-View-Template (MVT) is slightly different from MVC. In fact the main difference between the two patterns is that Django itself takes care of the Controller part (Software Code that controls the interactions between the Model and View), leaving us with the template. The template is a HTML file mixed with Django Template Language (DTL).
下图说明了 MVT 模式的每个组件如何协同交互来响应用户请求 -
The following diagram illustrates how each of the components of the MVT pattern interacts with each other to serve a user request −
开发人员提供模型、视图和模板,然后将其映射到网址,Django 展现魔力提供给用户。
The developer provides the Model, the view and the template then just maps it to a URL and Django does the magic to serve it to the user.