- What is Python?
- How to Install Python?
- Python Variables and Operators
- Python Loops
- Python Functions
- Python Files
- Python Errors and Exceptions
- Python Packages
- Python Classes and Objects
- Python Strings
- PostgreSQL Data Types
- Python Generators and Decorators
- Python Dictionary
- Python Date and Time
- Python List and Tuples
- Python Multithreading and Synchronization
- Python Modules
- What is Python bytecode?
- Python Regular Expressions
Python Panda Tutorial
- Python Pandas Tutorial
- Python Pandas Features
- Advantages and Disadvantages of Python Pandas
- Pandas Library In Python
- Pandas Series To Frame
- Python Dataframeaggregate and Assign
- Pandas Dataframe Describe
- Pandas Dataframe Mean
- Pandas Hist
- Pandas Dataframe Sum
- How to convert Pandas DataFrame to Numpy array
- Pandas Concatenation
- Pandas Shift
- Pandas Rolling
- Data Analysis With Pandas and Python
- How Python Panda Are Helpful For With Data Science
- Selenium Basics
- Selenium with Python Introduction and Installation
- Navigating links using get method Selenium Python
- Locating Single Elements in Selenium Python
- Locating Multiple elements in Selenium Python
Python Flask Tutorial
- How to Install Django and Set Up a Virtual Environment in 6 Steps
- Django MTV Architecture
- Django Models
- Django Views
- Django Templates
- Django Template Language
- Django Project Layout
- Django Admin Interface
- Django Database
- Django URLs and URLConf
- Django Redirects
- Django Cookies and Cookies Handling
- Django Caching
- Types of Caching in Django
- Django Sessions
- Django Forms Handling & Validation
- Django Exceptions & Error-handling
- Django Forms Validation
- Django Redirects
- Django Admin Interface
- Django Bootstrap
- Ajax in Django
- Django Migrations and Database Connectivity
- Django Web Hosting and IDE
- Django Admin Customization
- What is CRUD?
- Django ORM
- Django Request-Response Cycle
- Django ORM
- Making a basic_api with DRF
- Django Logging
- Django Applications
- Difference between Flask vs Django
- Difference between Django vs PHP
- Numpy Introduction
- NumPy– Environment Setup
- NumPy - Data Types
- NumPy Histogram
- Matrix in NumPy
- NumPy Arrays
- NumPy Array Functions
- Matrix Multiplication in NumPy
- NumPy Matrix Transpose
- NumPy Array Append
- NumPy empty array
- NumPy Linear Algebra
- NumPy sum
- NumPy Normal Distribution
- NumPy correlation
- Why we learn and use Numpy?
- Introduction To Tensorflow
- INTRODUCTION TO DEEP LEARNING
- EXPLAIN NEURAL NETWORK?
- CONVOLUTIONAL AND RECURRENT NEURAL NETWORK
- INTRODUCTION TO TENSORFLOW
- INSTALLATION OF TENSORFLOW
- TENSORBOARD VISUALIZATION
- Linear regression in tensorflow
- Word Embedding
- Difference between CNN And RNN
- Explain Keras
- Program elements in tensorflow
- Recurrent Neural Network
- Tensorflow Object Detection
- EXPLAIN MULTILAYER PERCEPTRON
- GRADIENT DESCENT OPTIMIZATION
Interview Questions & Answers
Django MTV Architecture
Django at its core is based on MVC architecture, it actually is implementing a variation of MVC, called MTV architecture.
There are some drawbacks of MVC architecture and it has certain areas where Django is offering a better-quality feature when using the MTV architecture.
MTV Architecture Components (Model, Template, and View)
This is a variation of the MVC pattern as you can see in the acronym itself the Template keyword replaces the Controller. Although, the Template is not exactly functioning as the controller and has some different properties than the controller.
The definitions of Model still remain the same that is, the Model contains the logical file structure of the project and is the middleware & data handler between database and view. The Model provides a definition of how the data formats as coming from the view so, it stores in the database and vice-versa, i.e., the retrieving information from the database transfers to the view in the displayable format.
The View in MTV architecture can look like the controller, but it’s not. The View in this MTV architecture is formatting the data via the model. In turn, it communicates to the database and that data which transfer to the template for viewing.
What Template is doing if everything View achieves in the first place?
Well, the template is making the life of a frontend developer easy that’s for sure. It also provides more development speed then the traditional MVC architecture would.
So, how is it doing that?
Template’s main goal is to keep everything that browser renders. The model’s data that’s coming from the server in different parts while integrating the same when the user interacts with the website. Here, the template layer in Django is more similar to the views layer in MVC pattern. This layer is more focused and with Django framework, it provides much more extendibility to the frontend developers than what MVC architecture was giving.
Working of MTV Architecture
Now for a better understanding of how Django implements the process, and what is the really important thing in this MTV architecture.
Django is literally a play between the requests and responses. So whenever our Template is updating it’s the input (request) we sent from here which on the server was seen by the View.
And, then it transports to the correct URL. It’s one of the important components of Django MTV architecture. There, the URL mapping in Django is actually done in regular expressions. These expressions are much more understandable than IP addresses. It also helps with the SEO task which we have discussed in the Django Features Tutorial.
Now after the sending of request to the correct URL, the app logic applies and the model initiates to correct response to the given request. Then that particular response is sent back to the View where it again examines the response and transmits it as an HTTP response or desired user format. Then, it again renders by the browser via Templates.
An easier real-life working of above functioning would be –
When you login in a website (Django based), you open the login page. It again happens without the need of the Model. It is because Views will process the request and send it to the URL of the login page. Then, it will be a response by the server, from there to the browser.
After that, you enter your credentials in the given Template, HTML form. From there the data is again sent to the view, this time this request rectifies and the model is given data. Then the Model reads and verifies the data that user provides within the connected database.
If the user data matches it will send the relevant user data like profile image, name and (other things depending on the type of website) to the Views. It will then format the same in desired response and will transmit the same to the client.
Otherwise, the Model will send a negative result to the Views. In turn, it will rout it to the login page again alongside an error message.
That’s how the Django MTV architecture is actually working.
Drawbacks of MVC Architecture
Two components are controlling View
In the MVC pattern, the view is the UI/ display logic of webpage. But in this MTV architecture, it generates/controls by two components, Model and Controller. That makes the testing process for View a bit difficult. As to fully test that, we will actually have to write the required model and controller first.
Too much load on Model Component
Model is doing all the work, be it transferring data from and to the database and operating on it. Also giving the appropriate results via applying the business logic. Single component accomplishes all these tasks.
Development Complexity is high
If we are implementing the MVC architecture’s approach over smaller projects then it would rather be a lengthy process of development. We will always need to understand the project structure and have to be cautious of the conventions that are using.
It has opposite effects on the smaller applications as they may not be too scalable. It can be like some ERP websites for college students, office private server etc. There this approach may make the system slower rather than faster.
Apply now for Advanced Python Training Course