Attention, Zin 的交互设计之路。

User interface, user experience and interactive design.

« 设计关乎选择与意图,而非偶然Yes, I am - Sophie Zelmani »

关于Django的MVC理解

可以肯定的说,Django使用的不是严谨的MVC结构,这一点在Django的faq中已经可以找到官方说法。按照开发组的想法,只做正确的事情而不只是“循规蹈矩”。在Web开发中并不是严格按照MVC结构才是好的框架,关键在于其重用性及执行效率。那Django是什么结构呢?他看起来更像是MTV,Model、Template、View,对比于MVC,Model、View、Controller,这里Template完成了MVC中View的任务,而Django中的View(视图)实际是在执行Controller的任务。
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.

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 is presented.

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 most logical to us.

欢迎发表看法:

您的讨论更有价值!

订阅

  • 欢迎订阅我的博客Attention!
  • 订阅到有道阅读

© 2008 7thPark.com. Some rights reserved! Z-blog inside. 粤ICP备05035430号

返回页首