The Structure of a Django Application

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this lecture on the structure of a django application it's a little early to be going through all the detail and there'll be some things that we're not really going to understand until a little bit later in the course but I wanted to sort of show you the lay of the land so that as we add features you realize that there's sort of a method to the madness and so Django is a way of building web applications Django has a pattern within itself that you know organizes folders in a certain way and puts files in certain places and we're gonna build these projects and applications and you're like why are these things organized the way they are well it has to do with the fact that if you go from one Django project to another Pengo project you can you know fit right in and understand how things are going to work so the important terminology that's I don't know a bit frustrating as there is projects and applications and from Django add to this notion has this notion of you have applications and you might have a project which is really basically a website and then you know some applications but if you had two projects you could share applications between them and so it's one or more applicant 1 or more applications per project with the ability to potentially reuse a application across multiple projects and so we're gonna work with my DJ for e samples which I hope you have downloaded somewhere at least so that you can look at the files look at the folders look at the names of the files look at the contents of the files this will all make more sense when you get a little farther down the road so here is an LS statement LS minus LD J free samples and hello this is this is within the folder DJ free samples there are two basic folders one is an effective project wide settings which is the name the same name as the folder that we're in such DJ free samples / DJ free samples and then there's the first application which is hello and there's a couple things here like the underscore underscore knit py you'll notice an empty file is just some bookkeeping that helps Python know that there are files that contain classes and objects in here settings dot py and URLs py + WG si dot P Y is kind of like the the traffic cop for this entire application that that routes things coming in to the right this entire project that routes things to the right application and then within the application we have some files and you really are going to learn a lot about object orientation you change its behavior by defining objects that accomplish things and then in effect registering those objects so a common thing will be to take something like you know admin dot py our models py create a data model and then tell the admin user interface that you didn't write how to show the your model and so you're right stuff in admin dot py to communicate into the admin user interface how your data model that jenkem currently knows nothing about is supposed to be shown etc etc so there's a lot of files and we will talk through these files now this is an example of request response it's a web application and so the what we'll talk about is once a request makes it into the server it's going to do some work and then produce a response but in that we're going to look at all of the work that goes back and forth and there's effectively like a routing step where it picks what part of your application to run this route this request to there is a view part which is going to receive it and potentially store data so I'm going to call that the model the storing of the data is certainly the model but the receiving of the impossibly new input data like you're going to create a new thing that would be the model and then the view at some point you got to finish it and send something back out and that's the purpose of the view we call this pattern for building web applications model view controller and it's not like you can't build applications any other way it's just by saying it's a terminology that I can say going forward that's the model that's the view and that's a controller function and I you don't have to know it right now but these are words that are loaded their loaded and have valuable meaning to us to be able to do so at some point in this picture on the left side we have a browser tom stands for the document object model and at some point the person clicks somewhere in the current web page they're looking at and web browser intercepts that and says okay I've got your click right here the web browser intercepts it and then makes a socket connection across the internet which we've seen before and then does a get request and that is what then goes into the server and so the three functions are the routing the views and the models and there is a overall configuration file the settings dot py which is sort of how you just say oh here's my view files read these view files read these model files so the settings that py kind of controls everything but when a request first comes in it consults URLs py and then for the project and then it will include URLs py s from each of the applications so once it's chosen what view to run it looks at the URL pulls out the pieces of the URL and finds the views in views dot py that's a Python file that has the the destinations for these incoming URLs there's a file called form stop py which we'll see later that is is used to make the the forms aspect the part that you fill in as pretty as possible and then we take the resulting data that we're going to send back and we merge that in through what's called a template and then if there's any data that we need stored we used we call the model and we store that in a database and there's this file called model dot py which informs how we store data in the database and then when that's all done we read potentially new data from the database merge that into a template and then send a response back to the browser and then that response is all shown to the end-user and so that really is the request into the server through a django application pulling data from various places merging a template back in and then sending a response back to the application so up next we're going to talk about virtual hosting now in general you're not going to have to worry about this it just kind of explains how something like Python anywhere is able to manage a whole lot of domains on a single system [Music] [Applause] [Music]
Info
Channel: Chuck Severance
Views: 22,226
Rating: 4.9349008 out of 5
Keywords:
Id: jmX27FrCqqs
Channel Id: undefined
Length: 7min 4sec (424 seconds)
Published: Tue Sep 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.