Django 为什么不叫MVC框架,官方给出了回答。

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Magicfrogman/article/details/79218581

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’sa subtle distinction.

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

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

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.

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.

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 mostlogical to us.


以下为翻译,水平不高,忍着点~


好吧,标准名称是有争议的。

通常所谓的MVC框架,‘view’的意思是向用户传递数据,它不关心数据长什么样子,仅关心数据如何传递。视图描述了你看到的数据是哪一个,而非如何呈现它。这就是微妙的区别。

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

此外,将内容和展示分离是明智之举,这就是模板的作用所在(templates).在django中,视图描述哪一个数据被呈现,而视图会委托一个模板去呈现数据。

那么,‘controller’在哪里适用呢?在django的实例中,它可能是框架本身,通过django url配置,机器发送请求到匹配的视图。

如果你是个缩略词癖好者,你或许可以说django是一个MTV框架,即modle,template,view(模型、模板、视图),这种细分更加贴合实际。

综合考虑后,理所当然的,不论如何命名,都是为了解决事情。django一向以符合逻辑的方式解决问题。(呵呵,最后这句刀补的)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章