{"id":80891,"date":"2021-06-17T09:00:15","date_gmt":"2021-06-17T03:30:15","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=80891"},"modified":"2021-06-17T09:00:15","modified_gmt":"2021-06-17T03:30:15","slug":"djangos-mvt-architecture","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/","title":{"rendered":"All You Need to Know About Django MVT Architecture"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In our previous article, we learned \u201cDjango\u2019s MVC Architecture\u201d. We have discussed the MVC (Model-View-Controller) in depth. We have seen the need to introduce the MVC architecture after discontinuing the old practice of having all the codes in a single file.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Well, Django at its core follows the MVC model but with a slight variation. The slighter variation being, the MVT (Model-View-Template). Let&#8217;s learn more about it.<\/span><\/p>\n<h3>Understanding Django MVT Architecture<\/h3>\n<p><span style=\"font-weight: 400\">In this architecture, the model remains the same, it provides the interface for storing the data in the database. Just like View in the MVC model, Django replaces it with a Template in its framework.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u201cThe controller part in the MVC model is taken care of by View in the MVT architecture\u201d. You must have come across this line surfing various articles, blogs, and books too, but, this isn\u2019t true. A Django view is not a controller. Let\u2019s understand what view is, and end your search, and kill the confusion for the final time.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let\u2019s discuss these three divisions in more detail.<\/span><\/p>\n<h4>1. Model<\/h4>\n<p><span style=\"font-weight: 400\">The model is going to work the same, as that in the MVC. It is held responsible for providing an interface for storing and maintaining the data in the database.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Generally, relational database management software such as MySQL, PostgreSQL, etc are put in use.\u00a0 <\/span><span style=\"font-weight: 400\">It responds to the request created by View.<\/span><\/p>\n<h4>2. View<\/h4>\n<p><span style=\"font-weight: 400\">It is that part of the system that accepts the user input made by the Template mode, retrieves the data from the database via the models, and sends back the response to the user.<\/span><\/p>\n<p><span style=\"font-weight: 400\">It takes care of the interpretation of the user\u2019s request to instruct the Model for data retrieval and also convert that data to present it in a user-friendly manner.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Django uses the idea of request-response by creating HTTP requests and response objects.<\/span><\/p>\n<p><span style=\"font-weight: 400\">When a page is called i.e., requested, Django creates an HTTP requests object. The view receives that request from the user and then accordingly processes the data in the database via the models. Then the view is held responsible for presenting the model to the user as an HTTP response object.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">It is also a very popular statement that the Django framework is the controller itself. But, it is also not entirely true. Django can do a lot more work than just handling requests and responses.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Django\u2019s Middleware is a framework that handles all the requests and response processing, after following all the necessary security and authentication checks.<\/span><\/p>\n<h4>3. Template<\/h4>\n<p><span style=\"font-weight: 400\">The template works in the same manner as that of View in the MVC model. It provides a user interface to users.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Template handles all the HTML, CSS pages, and displays the actual content of the web applications the user is using. <\/span><span style=\"font-weight: 400\">It takes all the user\u2019s input and provides easy interaction with the web applications.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Django uses Django Template Language (DML) by which one template can be used by multiple views to represent different kinds of data.<\/span><\/p>\n<h3>Control Flow Of Django MVT<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Control-Flow-Of-MVT.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81004\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Control-Flow-Of-MVT.jpg\" alt=\"Control Flow Of MVT\" width=\"1200\" height=\"550\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">1. The user asks for a URL request to fetch a resource, to Django through Template.<\/span><\/p>\n<p><span style=\"font-weight: 400\">2. Django searches for the URL request.<\/span><\/p>\n<p><span style=\"font-weight: 400\">3. The URL calls the View, as accordingly the coding is done.<\/span><\/p>\n<p><span style=\"font-weight: 400\">4. Then the View will interact with the Model and retrieve the suitable data from the database.<\/span><\/p>\n<p><span style=\"font-weight: 400\">5. Then View compiles that response created by the Model back to the Template. This way a request-response cycle takes place.<\/span><\/p>\n<h3>MVT vs MVC<\/h3>\n<p><span style=\"font-weight: 400\">After the thorough discussion, let\u2019s finally wrap up by mentioning the difference between the MVT and the MVC models.<\/span><\/p>\n<p><span style=\"font-weight: 400\">In MVC, we have a controller that handles both Model and View. Where in MVT, the View is held responsible for tackling all HTTP request-response operations and the Django framework manages the controller part.\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">MVC is not a suitable choice for developing a small web application due to its complexity, whereas MVT is the best option to develop both small and large applications.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Modification is not an easy task in MVC because of its hectic coding of the controller part. Modifying MVT is quite easy as the framework itself handles the controller part.\u00a0<\/span><\/p>\n<h3>Summary<\/h3>\n<p><span style=\"font-weight: 400\">So, with this, we come to the end of this article. If you are still confused between MVC and MVT, just keep in mind both work quite in a similar manner with just changes in terminologies.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Keep coding!<\/span><\/p>\n<p><span style=\"font-weight: 400\">Did you enjoy reading this article? Feel free to provide your feedback.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our previous article, we learned \u201cDjango\u2019s MVC Architecture\u201d. We have discussed the MVC (Model-View-Controller) in depth. We have seen the need to introduce the MVC architecture after discontinuing the old practice of having&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":81003,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3383],"tags":[3526,3527,3528],"class_list":["post-80891","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","tag-django-mvt","tag-django-mvt-architecture","tag-mvt-architecture-of-django"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>All You Need to Know About Django MVT Architecture - TechVidvan<\/title>\n<meta name=\"description\" content=\"Django MVT - The MVT is a software design pattern. It is a collection of three important components Model View and Template. Learn more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"All You Need to Know About Django MVT Architecture - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Django MVT - The MVT is a software design pattern. It is a collection of three important components Model View and Template. Learn more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-17T03:30:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Djangos-MVT-Architecture.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"All You Need to Know About Django MVT Architecture - TechVidvan","description":"Django MVT - The MVT is a software design pattern. It is a collection of three important components Model View and Template. Learn more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/","og_locale":"en_US","og_type":"article","og_title":"All You Need to Know About Django MVT Architecture - TechVidvan","og_description":"Django MVT - The MVT is a software design pattern. It is a collection of three important components Model View and Template. Learn more.","og_url":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-06-17T03:30:15+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Djangos-MVT-Architecture.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"All You Need to Know About Django MVT Architecture","datePublished":"2021-06-17T03:30:15+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/"},"wordCount":748,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Djangos-MVT-Architecture.jpg","keywords":["Django MVT","Django MVT Architecture","MVT Architecture of Django"],"articleSection":["Django Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/","url":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/","name":"All You Need to Know About Django MVT Architecture - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Djangos-MVT-Architecture.jpg","datePublished":"2021-06-17T03:30:15+00:00","description":"Django MVT - The MVT is a software design pattern. It is a collection of three important components Model View and Template. Learn more.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Djangos-MVT-Architecture.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Djangos-MVT-Architecture.jpg","width":1200,"height":628,"caption":"Django MVT Architecture"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/djangos-mvt-architecture\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"All You Need to Know About Django MVT Architecture"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=80891"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80891\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/81003"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=80891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=80891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=80891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}