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一向以符合邏輯的方式解決問題。(呵呵,最後這句刀補的)


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