This article is originally published on vision-secrets
In this post we will discuss about MVT pattern on Django.
The MVT (Model View Template) is a software design pattern. It is a collection of three important components Model View and Template. Although Django follows MVC pattern but maintains it’s own conventions. So, control is handled by the framework itself.
Basically Model act as Meditator Between Website Interface and Database. In Django We use Python Classes To make Models Which is nothing but Table in a Database. Class Attributes is a Columns of the Table in database and on this attributes we can set constraints like primary key , foreign key , Many to Many Relation , one to many Relation , etc. So using Models in Django makes Easy to connect with database. or we can say that model is whole logic of your project or business.
The View is used to execute the business logic and interact with a model to carry data and renders a template. View can be function based view or can be Class based view. when user requests something there is basically function or class is written to handle those requests. for example when user request ‘www.yoursitename.com/home’ . so basically here user requested for home page of your site and after this the view you written to handle this particular request it will return the response to the user in the form of HTML file or we can say that HTTTP response.
In Django, Templates are nothing but the HTML file which handles User Interface part completely. These Templates rendered when user requests for these templates. So basically templates are returned response by view to the user requests.
So lets look at this on Picture
Here you can see that user requests to your Django site. user has wrote some URL (Uniform Resource Locator) like “www.yoursite_name.com/page_name” after this, URL will match to the specified View , Now View will check the request object if there is any attributes related to Database it will fetch from or save those attributes to the database. If there is no Attributes related to Database simply it will look for HTML page (templates) to return as response but if it doesn’t found any templates it will show the error “404 page nor found”.
Comment down if you have any queries.