Is Django a MVC or MVT framework?
Asked Answered
P

5

9

I was wondering that whether Django is a MVC or MVT framework? I searched this question on net but didn't find any suitable or satisfactory answer.

Patricide answered 23/4, 2019 at 6:59 Comment(2)
Django is a Python web framework. And like most modern framework, Django supports the MVC pattern.Westonwestover
I am confused because when I searched the net tutorialspoint.com/django/django_overview.htm its quite ambiguous to decide whether Django is MVC or MVTPatricide
D
18

I found a partial answer to this question directly in Django's FAQs

https://docs.djangoproject.com/en/3.1/faq/general/#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

Quoting directly here for convenience:

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, 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.

Doherty answered 11/11, 2020 at 22:9 Comment(1)
I'm glad you posted this. I find this distinction to be super frustrating. I worked with MVC for 15+ years and when I'm working with Django there is literally no distinction to me other than naming. The "template" is just an MVC "view" and even in Ruby on Rails, the convention is to keep a view, just presentation. So if the MTV "template" is just presentation, that's the same. I would also argue the same for The django "view" and the MVC "controller"... updates model, hands off to "presentation" layer...Izzo
M
4

Django is an MVT based framework. And in that “M” stand for Model “V” stands for View & “T” stands for Template

Model: The Model is the logical data structure behind the entire application and is represented by a database(generally relational databases such as MySql, Postgres).

View: View is the main functionality part of Django architecture, where we write the business logic which is going to be responsible for request and response according to the client inputs.

Template: By the name itself it's showing its behavior. The template is the part that is used for the representation of HTML pages on the web browser.

If you want more specific detail about django mvt architecture, you can refer to this article which I found good and they have explained very well with a diagram representation Django MVT Architecture

Mispleading answered 5/1, 2021 at 14:19 Comment(1)
Id like to add, that it's not necessary to have business logic at the view level, it depends the principe you stick to - either thick models and thin views (the idea of keeping business logic in model level) and thin models and thick views (business at view layer)Baht
A
4

Django follows MVC pattern very closely but it uses slightly different terminology. Django is essentially an MTV (Model-Template-View) framework. Django uses the term Templates for Views and Views for Controller. In other words, in Django views are called templates, and controllers are called views. Hence our HTML code will be in templates and Python code will be in views and models.

A complete explanation of this can be found here - https://overiq.com/django-1-10/mvc-pattern-and-django/

Amidase answered 30/6, 2022 at 23:53 Comment(0)
M
2

Djnago follows MVT framework.M=model V=views. T=templates

https://www.geeksforgeeks.org/django-project-mvt-structure/

Manthei answered 2/7, 2022 at 8:9 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewLanthanum
W
0

No different bro, it's just matter of marketing and branding, python guys always try to say that we are different. You can see it clearly in the language syntax and implementation of every thing even OOP. For example when they interduce switch statement from python 3.10, they didn't call it switch.

Worms answered 7/6 at 22:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.