| 128 | | That's because Django isn't strictly a MVC framework. If you squint the right |
|---|
| 129 | | way, you can call Django's database layer the "Model", the view functions the |
|---|
| 130 | | "View", and the URL dispatcher the "Controller" -- but not really. |
|---|
| 131 | | |
|---|
| 132 | | In fact, you might say that Django is a "MTV" framework -- that is, Model, |
|---|
| 133 | | Template, and View make much more sense to us. |
|---|
| 134 | | |
|---|
| 135 | | So, although we've been strongly influenced by MVC -- especially in the |
|---|
| 136 | | separation-of-data-from-logic department -- we've also strayed from the path |
|---|
| 137 | | where it makes sense. |
|---|
| | 128 | Well, the standard names are debatable. |
|---|
| | 129 | |
|---|
| | 130 | In our interpretation of MVC, the "view" describes the data that gets presented |
|---|
| | 131 | to the user. It's not necessarily *how* the data *looks*, but *which* data is |
|---|
| | 132 | presented. The view describes *which data you see*, not *how you see it.* It's |
|---|
| | 133 | a subtle distinction. |
|---|
| | 134 | |
|---|
| | 135 | So, in our case, a "view" is the Python callback function for a particular URL, |
|---|
| | 136 | because that callback function describes which data is presented. |
|---|
| | 137 | |
|---|
| | 138 | Furthermore, it's sensible to separate content from presentation -- which is |
|---|
| | 139 | where templates come in. In Django, a "view" describes which data is presented, |
|---|
| | 140 | but a view normally delegates to a template, which describes *how* the data is |
|---|
| | 141 | presented. |
|---|
| | 142 | |
|---|
| | 143 | Where does the "controller" fit in, then? In Django's case, it's probably the |
|---|
| | 144 | framework itself: the machinery that sends a request to the appropriate view, |
|---|
| | 145 | according to the Django URL configuration. |
|---|
| | 146 | |
|---|
| | 147 | If you're hungry for acronyms, you might say that Django is a "MTV" framework |
|---|
| | 148 | -- that is, "model", "template", and "view." That breakdown makes much more |
|---|
| | 149 | sense. |
|---|
| | 150 | |
|---|
| | 151 | At the end of the day, of course, it comes down to getting stuff done. And, |
|---|
| | 152 | regardless of how things are named, Django gets stuff done in a way that's most |
|---|
| | 153 | logical to us. |
|---|