14

Learning Django MVC and the way I thought of it is:

Models are the database tables represented in Django as Python classes.
Views are the HTML returned from function in views.py.
Controllers are the actual functions themselves in views.py invoked from a HTTP request.

However I read on Wikipedia (at the time of writing):

... a regular-expression-based URL dispatcher ("Controller").

I would have thought the mapping of URLs to functions as routing - not the controller. But perhaps I am wrong - I guess I got my ideas because is ASP MVC the functions that handle the requests are contained in classes called Contollers...

InformedA
  • 2,991
  • 2
  • 19
  • 28
markmnl
  • 727
  • 1
  • 6
  • 18

1 Answers1

18

Your thoughts are not wrong. In MVC web-frameworks, people often speak of a Base Controller that performs the routing of a request to the actual Controller that handles the request.

This has come about because web frameworks generally have a single point where the request is received by the application and in pure MVC terms, this is where the job of the Controller starts.


The Django framework uses a non-idiomatic way of naming the parts of the MVC triad.

The mapping between Django names and the idiomatic terminology is:

Idiomatic term | Django term | Meaning
Model          | Model       | Contains all the business logic. At the very least the database access logic
View           | Template    | Responsible for generating the HTML and other UI
Controller     | View        | Contains the logic to tie the other parts together and to generate a response to a user request
Bart van Ingen Schenau
  • 71,712
  • 20
  • 110
  • 179