Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Django call it "views.py" instead of controller? [duplicate]

Tags:

python

django

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

Because in MVC, the "view" is usually the template...

like image 583
TIMEX Avatar asked Mar 09 '11 17:03

TIMEX


People also ask

Is Django view a controller?

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

What is view PY in Django?

Django views are Python functions that takes http requests and returns http response, like HTML documents. A web page that uses Django is full of views with different tasks and missions. Views are usually put in a file called views.py located on your app's folder.

What is the typical function of views PY?

A view function, or view for short, is a Python function that takes a web request and returns a web response. This response can be the HTML contents of a web page, or a redirect, or a 404 error, or an XML document, or an image . . . or anything, really.

Is Django MVC or MVP?

Django is a Python web framework. And like most modern framework, Django supports the MVC pattern.


1 Answers

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.

like image 144
Yuji 'Tomita' Tomita Avatar answered Oct 15 '22 17:10

Yuji 'Tomita' Tomita