{"id":80898,"date":"2021-06-11T09:00:37","date_gmt":"2021-06-11T03:30:37","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=80898"},"modified":"2021-06-11T09:00:37","modified_gmt":"2021-06-11T03:30:37","slug":"django-mvc-architecture","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/","title":{"rendered":"Learn Django Architecture in just 5 minutes"},"content":{"rendered":"<p><span style=\"font-weight: 400\">For interacting with any websites out there on the Internet we need 3 things, Input, Processing, and Output. In technical words, Input logic, Business logic, and UI logic.\u00a0\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Back in times, when our web applications were not very interactive and we as a user did not demand much from it, it was quite effective to have all the 3 components clubbed in one. The early web pages were majorly text-based, with no special design and page structures, the internet connections were slow and technology limited.<\/span><\/p>\n<p><span style=\"font-weight: 400\">But, today, our web applications are very smart. Machine learning algorithms are introduced to understand customer behavior and boost customer engagements, using AI chatbots to improve user experience and all the other magical things out there. We need a proper division of work.<\/span><\/p>\n<p><span style=\"font-weight: 400\">For solving this problem, we have an approach popularly known as MVC. MVC stands for Model, View, and Controller. MVC solves the drawback of the traditional approach of having codes in one file.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The UI logic is an HTML, CSS page made for the users to interact with the system. Business logic is the part that handles the output. The Input logic takes the input and sends it to the Business logic part for processing the user\u2019s request.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let\u2019s understand the MVC model in more depth.<\/span><\/p>\n<h3>Model-View-Controller in Django<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/image2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80952\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/image2.jpg\" alt=\"MVC in Django\" width=\"720\" height=\"480\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">Let us discuss this in a way in which a user looks up a web application. The first thing being the user interface, i.e., View, then the Controller, and finally the Model.<\/span><\/p>\n<h4>1. View<\/h4>\n<p><span style=\"font-weight: 400\">View provides a user interface, it displays the actual view of the web application you are using. It is an interactive end for the users, which provides data stored in the form of charts, tables, diagrams, text boxes, dropdown menus, etc.<\/span><\/p>\n<p><span style=\"font-weight: 400\">It takes the user\u2019s input and informs the Controller. The Controller further passes the request to the Model. Controller and Model tell the view of the things to display the users. It represents the UI logic.<\/span><\/p>\n<h4>2. Controller<\/h4>\n<p><span style=\"font-weight: 400\">The Controller may be referred to as the most important part of the MVC model. The controller is that part of the MVC model, which accepts user input and performs the corresponding updates both in model and view.\u00a0 It acts as a bridge between a user and the system, i.e., between View and Model.<\/span><\/p>\n<p><span style=\"font-weight: 400\">It provides the user the option to make an input by displaying the appropriate View. The Controller uses logic to interpret the user\u2019s input and make a request to the Model. The Model understands and grabs the data, the controller then understands the output, converts it back to the appropriate format, and passes the message back to the View for the users to see that. It represents the Input logic.<\/span><\/p>\n<h4>3. Model<\/h4>\n<p><span style=\"font-weight: 400\">The Model is the lowest level of the MVC pattern which is held responsible for storing and maintaining data. This level tells where the web application\u2019s data is stored. It responds to the instructions from the Controller and also to the requests from the View. It represents Business logic.<\/span><\/p>\n<p><b>MVC Real life Example<\/b><\/p>\n<p><span style=\"font-weight: 400\">1. Let\u2019s assume you go to a coffee shop. You are the customer, you are not going to make the coffee, right?<\/span><\/p>\n<p><span style=\"font-weight: 400\">2. Now the waiter comes to you and asks for the order. He just wrote down what you want, he is also not going to make coffee for you, he doesn\u2019t know how to make it.<\/span><\/p>\n<p><span style=\"font-weight: 400\">3. The waiter gives your order to the cook in the kitchen.<\/span><\/p>\n<p><span style=\"font-weight: 400\">4. The cook then prepares your coffee with all the ingredients which he has on the shelf.<\/span><\/p>\n<p><span style=\"font-weight: 400\">5. Cook finally handed over the coffee to the waiter. Now the waiter brings that coffee to you.<\/span><\/p>\n<p><span style=\"font-weight: 400\">So in this case:<\/span><\/p>\n<p><span style=\"font-weight: 400\">View = You<\/span><\/p>\n<p><span style=\"font-weight: 400\">Controller = Waiter<\/span><\/p>\n<p><span style=\"font-weight: 400\">Model = Cook<\/span><\/p>\n<p><span style=\"font-weight: 400\">Data = Shelf<\/span><\/p>\n<h3>Django MVT Pattern<\/h3>\n<p><span style=\"font-weight: 400\">Django follows MVT ( Model-View-Template) architecture, wherein Template is replaced for View and View for Controller. The working is the same with just change in the terminologies.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Though, there is a misconception that the view in MVT works the same as the controller in MVC. But it is not actually true. We will discuss this in more depth in the next article on Django\u2019s MVT architecture.<\/span><\/p>\n<p><span style=\"font-weight: 400\">For the time being, this image will help you to know the overview.\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Architecture-and-components-normal-image.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80951\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Architecture-and-components-normal-image.jpg\" alt=\"Django Architecture and Components\" width=\"900\" height=\"628\" \/><\/a><\/p>\n<h3>Advantages of Django Architecture<\/h3>\n<h4>1. Rapid Development<\/h4>\n<p><span style=\"font-weight: 400\">As there is the correct distribution of work between 3 components, rapid application development is achieved. A programmer can work on views in the MVC model, one on the Controller, and one on the Model. This easily distributes the work among the programmers hence help in developing the applications fast.<\/span><\/p>\n<h4>2. Loosely Coupled<\/h4>\n<p><span style=\"font-weight: 400\">The Django applications have three different components working one at a time. All the 3 components are designed individually so this has made security very important aspects during the development<\/span><\/p>\n<h4>3. Asynchronous Techniques<\/h4>\n<p><span style=\"font-weight: 400\">The MVC architecture can easily integrate with the Javascript Framework. This helps the applications to work with PDF files and desktop widgets.\u00a0<\/span><\/p>\n<h4>4. Modification is easy<\/h4>\n<p><span style=\"font-weight: 400\">The modification is necessary for any growing web application. Even the smallest changes of colors, fonts, images are quite easy while working with the MVC architecture. As the 3 components are loosely coupled and don\u2019t depend upon others, the changes made in View have nothing to do with the Model.<\/span><\/p>\n<h4>5. Returns Data Without Formatting<\/h4>\n<p><span style=\"font-weight: 400\">MVC returns data without applying it to format. That means the same components can be used with any other framework.<\/span><\/p>\n<h4>6. Seo Friendly<\/h4>\n<p><span style=\"font-weight: 400\">We have already discussed this point in our articles. MVC model helps in creating SEO-friendly web applications.<\/span><\/p>\n<h3><b>Disadvantages of using MVC Architecture of Django<\/b><\/h3>\n<p><span style=\"font-weight: 400\">1. The Navigation of the framework can be challenging sometimes. The introduction of three layers with abstractions involved makes the users learn the decomposition criteria of MVC.<\/span><\/p>\n<p><span style=\"font-weight: 400\">2. Need multiple developers to perform parallel programming.<\/span><\/p>\n<p><span style=\"font-weight: 400\">3. Knowledge of multiple technologies is necessary.<\/span><\/p>\n<p><span style=\"font-weight: 400\">4. Maintenance of lots of codes in Controller.\u00a0<\/span><\/p>\n<h3>Summary<\/h3>\n<p><span style=\"font-weight: 400\">This tutorial discussed the MVC model (Model-View-Controller), the MVT model (Model-View-Template), and the advantages and disadvantages of the MVC model.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For interacting with any websites out there on the Internet we need 3 things, Input, Processing, and Output. In technical words, Input logic, Business logic, and UI logic.\u00a0\u00a0\u00a0 Back in times, when our web&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":80950,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3383],"tags":[3536,3537],"class_list":["post-80898","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","tag-django-architecture","tag-django-mvc-architecture"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Learn Django Architecture in just 5 minutes - TechVidvan<\/title>\n<meta name=\"description\" content=\"As you already know, Django is a Python web framework. And like most modern framework, Django supports the MVC pattern. Learn more about it.\" \/>\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\/django-mvc-architecture\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn Django Architecture in just 5 minutes - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"As you already know, Django is a Python web framework. And like most modern framework, Django supports the MVC pattern. Learn more about it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/django-mvc-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-11T03:30:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Architecture-and-components.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=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn Django Architecture in just 5 minutes - TechVidvan","description":"As you already know, Django is a Python web framework. And like most modern framework, Django supports the MVC pattern. Learn more about it.","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\/django-mvc-architecture\/","og_locale":"en_US","og_type":"article","og_title":"Learn Django Architecture in just 5 minutes - TechVidvan","og_description":"As you already know, Django is a Python web framework. And like most modern framework, Django supports the MVC pattern. Learn more about it.","og_url":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-06-11T03:30:37+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Architecture-and-components.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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Learn Django Architecture in just 5 minutes","datePublished":"2021-06-11T03:30:37+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/"},"wordCount":993,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Architecture-and-components.jpg","keywords":["Django Architecture","Django MVC Architecture"],"articleSection":["Django Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/","url":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/","name":"Learn Django Architecture in just 5 minutes - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Architecture-and-components.jpg","datePublished":"2021-06-11T03:30:37+00:00","description":"As you already know, Django is a Python web framework. And like most modern framework, Django supports the MVC pattern. Learn more about it.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Architecture-and-components.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Architecture-and-components.jpg","width":1200,"height":628,"caption":"Django Architecture"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/django-mvc-architecture\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Learn Django Architecture in just 5 minutes"}]},{"@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\/80898","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=80898"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80898\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/80950"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=80898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=80898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=80898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}