{"id":75304,"date":"2020-01-18T14:18:49","date_gmt":"2020-01-18T08:48:49","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?p=75304"},"modified":"2024-04-12T14:17:13","modified_gmt":"2024-04-12T08:47:13","slug":"the-mtv-development-pattern","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/","title":{"rendered":"The MTV Development Pattern"},"content":{"rendered":"<p>Before we delve into any more code, let\u2019s take a moment to consider the overall design of a database-driven Django Web application. As we mentioned in previous chapters, Django is designed to encourage loose coupling and strict separation between pieces of an application. If you follow this philosophy, it\u2019s easy to make changes to one particular piece of the application without affecting the other pieces. In view functions, for instance, we discussed the importance of separating the business logic from the presentation logic by using a template system. With the database layer, we\u2019re applying that same philosophy to data access logic.<\/p>\n<p>Those three pieces together \u2014 data access logic, business logic, and presentation logic \u2014 comprise a concept that\u2019s sometimes called the <em>Model-View-Controller<\/em> (MVC) pattern of software architecture. In this pattern, \u201cModel\u201d refers to the data access layer, \u201cView\u201d refers to the part of the system that selects what to display and how to display it, and \u201cController\u201d refers to the part of the system that decides which view to use, depending on user input, accessing the model as needed.<\/p>\n<p><strong>Why the Acronym?<\/strong>&nbsp; The goal of explicitly defining patterns such as MVC is mostly to streamline communication among developers. Instead of having to tell your coworkers, \u201cLet\u2019s make an abstraction of the data access, then let\u2019s have a separate layer that handles data display, and let\u2019s put a layer in the middle that regulates this,\u201d you can take advantage of a shared vocabulary and say, \u201cLet\u2019s use the MVC pattern here.\u201d<\/p>\n<p>Django follows this MVC pattern closely enough that it can be called an MVC framework. Here\u2019s roughly how the M, V, and C break down in Django:<\/p>\n<ul>\n<li><em>M<\/em>, the data-access portion, is handled by Django\u2019s database layer, which is described in this chapter.<\/li>\n<li><em>V<\/em>, the portion that selects which data to display and how to display it, is handled by views and templates.<\/li>\n<li><em>C<\/em>, the portion that delegates to a view depending on user input, is handled by the framework itself by following your URLconf and calling the appropriate Python function for the given URL.<\/li>\n<\/ul>\n<p>Because the \u201cC\u201d is handled by the framework itself and most of the excitement in Django happens in models, templates, and views, Django has been referred to as an <em>MTV framework<\/em>. In the MTV development pattern,<\/p>\n<ul>\n<li><em>M<\/em> stands for \u201cModel,\u201d the data access layer. This layer contains anything and everything about the data: how to access it, how to validate it, which behaviors it has, and the relationships between the data.<\/li>\n<li><em>T<\/em> stands for \u201cTemplate,\u201d the presentation layer. This layer contains presentation-related decisions: how something should be displayed on a Web page or other type of document.<\/li>\n<li><em>V<\/em> stands for \u201cView,\u201d the business logic layer. This layer contains the logic that access the model and defers to the appropriate template(s). You can think of it as the bridge between models and templates.<\/li>\n<\/ul>\n<p>If you\u2019re familiar with other MVC Web-development frameworks, such as Ruby on Rails, you may consider Django views to be the \u201ccontrollers\u201d and Django templates to be the \u201cviews.\u201d This is an unfortunate confusion brought about by differing interpretations of MVC. In Django\u2019s interpretation of MVC, the \u201cview\u201d describes the data that gets presented to the user; it\u2019s not necessarily just <em>how<\/em> the data looks, but <em>which<\/em> data is presented. In contrast, Ruby on Rails and similar frameworks suggest that the controller\u2019s job includes deciding which data gets presented to the user, whereas the view is strictly <em>how<\/em> the data looks, not <em>which<\/em> data is presented.<\/p>\n<p>Neither interpretation is more \u201ccorrect\u201d than the other. The important thing is to understand the underlying concepts.<\/p>\n\n\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/certified-django-developer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Back to Tutorial<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before we delve into any more code, let\u2019s take a moment to consider the overall design of a database-driven Django Web application. As we mentioned in previous chapters, Django is designed to encourage loose coupling and strict separation between pieces of an application. If you follow this philosophy, it\u2019s easy to make changes to one&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[8655],"tags":[8677],"class_list":["post-75304","page","type-page","status-publish","hentry","category-django-web-development","tag-the-mtv-development-pattern"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The MTV Development Pattern - Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The MTV Development Pattern - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Before we delve into any more code, let\u2019s take a moment to consider the overall design of a database-driven Django Web application. As we mentioned in previous chapters, Django is designed to encourage loose coupling and strict separation between pieces of an application. If you follow this philosophy, it\u2019s easy to make changes to one...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:47:13+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/\",\"name\":\"The MTV Development Pattern - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2020-01-18T08:48:49+00:00\",\"dateModified\":\"2024-04-12T08:47:13+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The MTV Development Pattern\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The MTV Development Pattern - Tutorial","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:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/","og_locale":"en_US","og_type":"article","og_title":"The MTV Development Pattern - Tutorial","og_description":"Before we delve into any more code, let\u2019s take a moment to consider the overall design of a database-driven Django Web application. As we mentioned in previous chapters, Django is designed to encourage loose coupling and strict separation between pieces of an application. If you follow this philosophy, it\u2019s easy to make changes to one...","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:47:13+00:00","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/","name":"The MTV Development Pattern - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2020-01-18T08:48:49+00:00","dateModified":"2024-04-12T08:47:13+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/the-mtv-development-pattern\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"The MTV Development Pattern"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=75304"}],"version-history":[{"count":4,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75304\/revisions"}],"predecessor-version":[{"id":83805,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75304\/revisions\/83805"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=75304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=75304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=75304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}