#9 Django tutorials | Model View Template in Django | MVT

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome back aliens my name is Evans ready and let's continue the series on Django now there's one important concept in Django which is MV E or MTV now it is very similar to MVC on different web frameworks available but in Django we use MTV or fvt now it stands for Model View template but why do we need that so let's start with a simple web page so of course right as a user you go to a particular website and you fetch a page now that page can be a static page because in a normal page we have two important things one is the layout of the page and then the data as well now data is something which we want right as a user we want to see a detail we want to use a data but with that we also need a layout of course you will not go to any website when you bet you don't have a layout evenly when you go to Amazon and if you see your order history so you will see all the orders there but then you you get or everything in a proper layout now that layout will be designed in HTML CSS or maybe front-end JavaScript and the data will be coming from database or maybe you can have static content in a stone itself you know everything will static but what if you want a dynamic content example as for the user example on Amazon if you see or the history you will see your order history right you will not see my order history so data on that page is different for everyone so basically when you visit a page let's say or the history on Amazon everyone will get a different data so that data is actually coming from database so yes data is important the layout is important and there is one important thing which is the business logic of course right when you want to do something on the website you been already there for that as web application nowadays so in the web application sometime you perform some operations you build your business logic example let's say if you go to again Amazon if you want to add a perk in a cart that's one process so on the Amazon server they will be doing some processing now we have to write that code somewhere so basically we need three things the data the layout and the logic and to write you in fact we can write everything in one page so we can build a page where you will have the out where you will have the data where you have the logic but you know sometimes it's better to separate those things from one another in fact we call them as separation of concerns so we have three concerns we are separating them and that's where in software engineering we have different software design patterns one of them is M V T so M V T is Model View template now as name suggests model is for data yes so the data is seven coming from database and that can be linked with the model object right so when you say model in your application you might be having different in entities and every entity will have its own model object now that can be linked with database again you will see the examples later and then on the other hand we have templates now this template will be normal HTML right in that HTML yes HTML CSS and front-end JavaScript but it will also have DTL which is Django template language so if you let's say if you want to introduce some dynamic data in your page that can be done with the help of DTL so we will be having that layout and the detail there so this data will be coming from the model object right but who will link this and how you will call all these things you know you have to provide this navigation somewhere so let's go back again so let's say as a user you want to fetch data so you are sending a request this request will go to your application you have web application maybe if you are using Django there so it will go to Django framework now in Django framework whenever you build a project you will get a very specific file which is URLs right if you remember we have done that so in the urs you do the all the mapping right so from where you will get the request and then what will happen so that navigation will be sent to the views if you remember in urs you do that you save use dot something so it will go to views now what is view we have not talked about that so the business logic which we want to write will be done in views I know that's bit tricky because normally when you say view it should be a should be a page but that's not the case in views we actually write the business logic right and then this views will use the model object and the template so what data has to be sent on the template will be decided by view right and the with the models will be done through view and that's the importance of this Model View template and that's why we say it's a MVC framework right so it's quite useful to segregate your concerns is submitting your concerns model will work with data views will work with logic and template will work with layouts so that's about MBTs so just to recap a user will send a request which will go to URLs in the URL it will check ok we have to call views because that's what we do in the code and inside this view you will write the logic plus you will also connecting your template and the model so you will see all this example in the further videos now you can also read it the same concept with MVC in fact in other frameworks like spring we have MVC and then we say we have Model View controller so whatever we is done in model in Django same thing happens in MVC which is M death model then we have view so that the worth of this template in those framework is done with view and the view job will be done with controller not exactly because in other frameworks we have to configure the controller as well we don't have to do that in Django because it will be done by the Django framework so they are quite similar but with this main difference which is in views we don't control stuff right that's the thing about MVT if you are getting confused just ignored MVC focus on MVT everything Model View and template so I hope you are enjoying this by [Music]
Info
Channel: Telusko
Views: 116,766
Rating: undefined out of 5
Keywords: telusko, navin, reddy, tutorial, java, python
Id: GGkFg52Ot5o
Channel Id: undefined
Length: 5min 54sec (354 seconds)
Published: Tue Jun 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.