为什么Django称它为“视图”?py”而不是控制器吗?(复制)

时间:2021-08-12 20:28:20

Possible Duplicate:
Confused by Django's claim to MVC, what is it exactly?

可能的重复:被Django对MVC的声明搞糊涂了,它到底是什么?

Because in MVC, the "view" is usually the template...

因为在MVC中,“视图”通常是模板…

3 个解决方案

#1


20  

Django appears to be a MVC framework, but you call the Controller the “view”, and the View the “template”. How come you don’t use the standard names?

Well, the standard names are debatable.

标准的名字是有争议的。

In our interpretation of MVC, the “view” describes the data that gets presented to the user. It’s not necessarily how the data looks, but which data is presented. The view describes which data you see, not how you see it. It’s a subtle distinction.

在我们对MVC的解释中,“视图”描述了呈现给用户的数据。这并不一定是数据的外观,而是数据的呈现方式。视图描述了您所看到的数据,而不是您如何看待它。这是一个微妙的区别。

So, in our case, a “view” is the Python callback function for a particular URL, because that callback function describes which data is presented.

因此,在我们的例子中,“视图”是针对特定URL的Python回调函数,因为这个回调函数描述了呈现的数据。

Furthermore, it’s sensible to separate content from presentation – which is where templates come in. In Django, a “view” describes which data is presented, but a view normally delegates to a template, which describes how the data is presented.

此外,将内容与表示分离是明智的——这正是模板的用武之地。在Django中,“视图”描述呈现的数据,但是视图通常委托给模板,模板描述数据的呈现方式。

Where does the “controller” fit in, then? In Django’s case, it’s probably the framework itself: the machinery that sends a request to the appropriate view, according to the Django URL configuration.

那么,“控制器”在哪里呢?在Django的例子中,可能是框架本身:根据Django URL配置向适当的视图发送请求的机器。

If you’re hungry for acronyms, you might say that Django is a “MTV” framework – that is, “model”, “template”, and “view.” That breakdown makes much more sense.

如果你对首字母缩略词很感兴趣,你可能会说Django是一个“MTV”框架——即“model”、“template”和“view”。这种崩溃更有意义。

At the end of the day, of course, it comes down to getting stuff done. And, regardless of how things are named, Django gets stuff done in a way that’s most logical to us.

当然,归根结底还是要把事情做完。而且,不管事物是如何命名的,Django以最符合逻辑的方式完成事情。

#2


2  

The answer is in the FAQ: http://docs.djangoproject.com/en/dev/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names

答案在FAQ中:http://docs.djangoproject.com/en/dev/faq/general/#django- appearance -to- a-mvc-frame -but-you-call- The -view- view- view- how- you- come- to- go- use- The -standard-name

#3


2  

Yes Django is not MVC, Django prefers to call its MVC implementation MTV, for Model Template View.

是的,Django不是MVC, Django喜欢将它的MVC实现命名为MTV,用于模型模板视图。

See this blog for more on Django and MTV

更多关于《被解救的姜戈》和MTV的信息,请参见本博客

#1


20  

Django appears to be a MVC framework, but you call the Controller the “view”, and the View the “template”. How come you don’t use the standard names?

Well, the standard names are debatable.

标准的名字是有争议的。

In our interpretation of MVC, the “view” describes the data that gets presented to the user. It’s not necessarily how the data looks, but which data is presented. The view describes which data you see, not how you see it. It’s a subtle distinction.

在我们对MVC的解释中,“视图”描述了呈现给用户的数据。这并不一定是数据的外观,而是数据的呈现方式。视图描述了您所看到的数据,而不是您如何看待它。这是一个微妙的区别。

So, in our case, a “view” is the Python callback function for a particular URL, because that callback function describes which data is presented.

因此,在我们的例子中,“视图”是针对特定URL的Python回调函数,因为这个回调函数描述了呈现的数据。

Furthermore, it’s sensible to separate content from presentation – which is where templates come in. In Django, a “view” describes which data is presented, but a view normally delegates to a template, which describes how the data is presented.

此外,将内容与表示分离是明智的——这正是模板的用武之地。在Django中,“视图”描述呈现的数据,但是视图通常委托给模板,模板描述数据的呈现方式。

Where does the “controller” fit in, then? In Django’s case, it’s probably the framework itself: the machinery that sends a request to the appropriate view, according to the Django URL configuration.

那么,“控制器”在哪里呢?在Django的例子中,可能是框架本身:根据Django URL配置向适当的视图发送请求的机器。

If you’re hungry for acronyms, you might say that Django is a “MTV” framework – that is, “model”, “template”, and “view.” That breakdown makes much more sense.

如果你对首字母缩略词很感兴趣,你可能会说Django是一个“MTV”框架——即“model”、“template”和“view”。这种崩溃更有意义。

At the end of the day, of course, it comes down to getting stuff done. And, regardless of how things are named, Django gets stuff done in a way that’s most logical to us.

当然,归根结底还是要把事情做完。而且,不管事物是如何命名的,Django以最符合逻辑的方式完成事情。

#2


2  

The answer is in the FAQ: http://docs.djangoproject.com/en/dev/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names

答案在FAQ中:http://docs.djangoproject.com/en/dev/faq/general/#django- appearance -to- a-mvc-frame -but-you-call- The -view- view- view- how- you- come- to- go- use- The -standard-name

#3


2  

Yes Django is not MVC, Django prefers to call its MVC implementation MTV, for Model Template View.

是的,Django不是MVC, Django喜欢将它的MVC实现命名为MTV,用于模型模板视图。

See this blog for more on Django and MTV

更多关于《被解救的姜戈》和MTV的信息,请参见本博客