understanding Model View Controller(MVC) in Django
What is Model View Controller? We call it in short MVC. It's a software architecture pattern that is used to devide the complex software into simple parts based on the functionality. When we use Google for web search, we simply open Google and search for "food" let's say. Then google will show us results about food. This what we see. But, actually what happens is when we search google with keyword "food", browser sends request to google server with query parameter as "food". Then, it will query the google search index database and fetches the records from the database. Let's say, these records not in the order as we see it in the google webpage. So, Google has to process queried database records to put them in order to display it. By using the processed data It will generate the html document to present it to the user.
To simplify the software development software architects divided the process into 3 parts. 1.Model, 2.Controller and 3.View
- It deals with the database operations.
- Creating and updating the tables
- Fetching and updating the data in the database
- It deals with processing of data. Some developers also call it as Business Logic part.
- Process the data and generate it into required format to be sent to next layer ie.View.
- It deals with presenting the data to the end user.
- It recieves the data from the controller and generates the html to present it to the enduser.
The django framework also follows the MVC architecture pattern. But, It just renamed MVC into MTV(Model, Template, View) .
Advantages of Model View Controller Architecture
- Multiple developers can work simultaneously.
- It will be easy to divide and distribute the work among multiple developers.
- It can be easy to debug and fix the errors because of separation of responsibilities.