Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused by Django's claim to MVC, what is it exactly?

So what exactly is Django implementing?

Seems like there are

Models
Views
Templates

Models = Database mappings

Views = Grab relevant data from the models and formats it via templates

Templates = Display HTML depending on data given by Views

EDIT: S. Lott cleared a lot up with this in an edit to a previous post, but I would still like to hear other feedback. Thanks!

Is this correct? It really seems like Django is nowhere near the same as MVC and just confuses people by calling it that.

like image 819
DevDevDev Avatar asked Aug 18 '09 00:08

DevDevDev


People also ask

Why is Django not MVC?

DJANGO MVC - MVT Pattern The Model-View-Template (MVT) is slightly different from MVC. In fact the main difference between the two patterns is that Django itself takes care of the Controller part (Software Code that controls the interactions between the Model and View), leaving us with the template.

Is Django based on MVC?

Django appears to be a MVC framework, but you call the Controller the “view”, and the View the “template”.

Why is Django MVC?

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.

What is the controller in Django?

A controller is the heart of the system, it steers everything. For a web framework, this means handling requests and responses, setting up database connections and loading add-ons. For this, Django reads a settings file so that it knows what to load and set up.


1 Answers

Django's developers have a slightly non-traditional view on the MVC paradigm. They actually address this question in their FAQs, which you can read here. In their own words:

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.

like image 61
mipadi Avatar answered Oct 08 '22 18:10

mipadi