Django 与模型视图控制器 [英] Django vs. Model View Controller

查看:24
本文介绍了Django 与模型视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下 Django 和模型视图控制器模式之间的区别在哪里?

Can somebody explain me where the diferences are between Django and the Model View Controller pattern?

在功能上,我们可以从这些差异中得到什么——例如,将 Django 与 Ruby on Rails 进行比较,有什么不同?

Functionally, what can we expect from those differences — i.e. what works differently comparing Django to, for example, Ruby on Rails?

推荐答案

根据Django Book,Django遵循MVC 模式非常接近,可以称为 MVC 框架.

According to the Django Book, Django follows the MVC pattern closely enough to be called an MVC framework.

Django 被称为 MTV 框架,因为控制器由框架本身处理,并且大部分激动人心的事情发生在模型、模板和视图中.

Django has been referred to as an MTV framework because the controller is handled by the framework itself and most of the excitement happens in models, templates and views.

您可以在此处阅读有关 MTV/MVC 的更多信息:

You can read more about MTV / MVC here:

MTV(或MVC)开发模式

如果你熟悉其他 MVCWeb 开发框架,例如Ruby on Rails,你可以考虑 Django视图成为控制器和Django 模板作为视图.

If you’re familiar with other MVC Web-development frameworks, such as Ruby on Rails, you may consider Django views to be the controllers and Django templates to be the views.

这是一个不幸的混淆不同造成的MVC的解释.

This is an unfortunate confusion brought about by differing interpretations of MVC.

在 Django 对 MVC 的解释中,视图描述呈现的数据给用户;这不一定只是数据看起来如何,但哪些数据是呈现.

In Django’s interpretation of MVC, the view describes the data that gets presented to the user; it’s not necessarily just how the data looks, but which data is presented.

相比之下,Ruby on Rails和类似的框架表明控制者的工作包括决定哪些数据会呈现给用户,而观点是严格如何数据看起来,而不是哪个数据呈现.

In contrast, Ruby on Rails and similar frameworks suggest that the controller’s job includes deciding which data gets presented to the user, whereas the view is strictly how the data looks, not which data is presented.

这篇关于Django 与模型视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆