Django vs. Model View Controller [closed] Django vs. Model View Controller [closed] django django

Django vs. Model View Controller [closed]


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

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.

You can read more about MTV / MVC here:

The MTV (or MVC) Development Pattern

If you’re familiar with other MVCWeb-development frameworks, such asRuby on Rails, you may consider Djangoviews to be the controllers andDjango templates to be the views.

This is an unfortunate confusionbrought about by differinginterpretations of MVC.

In Django’s interpretation of MVC, the viewdescribes the data that gets presentedto the user; it’s not necessarily justhow the data looks, but which data ispresented.

In contrast, Ruby on Railsand similar frameworks suggest thatthe controller’s job includes decidingwhich data gets presented to the user,whereas the view is strictly how thedata looks, not which data ispresented.


The Django FAQ itself is a decent place to start:

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.

...

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.

Bear in mind that “Model View Controller” is just a pattern, i.e. an attempt to describe a common architecture. So a better question might be “How well does Django fit the Model View Controller pattern?”


When you code, not thinking about names of framework pieces, there are no susbtantive differences betw, for example RoR. But it depends on the use you give models, since on Django they easily contain some logic that on other frameworks would stay at controller level.

The view on Django tends to be a set of queries for fetching data, and pass them to the template.