3. Project Structure – Django by Example

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello world Noah here welcome to the next episode of Django by example in this episode we're going to start a new Django project and take a look at the structure of the project and what each individual file will do for us now to write all of our code for Django we're going to be using an IDE called PyCharm that's by a company called JetBrains PyCharm is an incredible ide for pretty much anything python that you could possibly want to do but it has incredible support for Django it has all kinds of built-in features that are really really nice and makes everything really easy now you can go to jeffrey INSCOM slash PyCharm link in the description to download it and you're going to need to download the professional edition because the professional Edition as you'll see contains support for web development aka Django if you download the community edition you won't get all of the amazing support for Django that you will with the professional Edition now you can download a 30-day free trial but if you don't want to pay for it and if you're a student and high school or college you can go to JetBrains comm slash student and get all of JetBrains products for free of course including PyCharm all you have to do is show proof that you're a student I think you just upload a student ID or something and you get all of their programs free for a year and you can renew every year that you're a student so I highly recommend that you fill out this form it's super easy super quick and you can get all of their incredible products for free in the meantime though the 30-day free trial will be more than enough so once you have pycharm installed you're going to want to go ahead and open it up as I will do here and you should be presented with the start screen for pycharm we'll go ahead and create a new project and we're going to want to choose Django of course we're creating a Django project we're gonna go ahead and give this a name so since we're making a programming database I'm going to name the project programming database you want to pick your Python interpreter I'm gonna be using Python 3.6 although you shouldn't notice a difference really between Python 2 or 3 or an earlier version of Python 3 because Django is supported by Python 2 and 3/4 the template language you want to do Django and we basically leave all this stuff the same but for application name we're gonna write PDB underscore app PDB for programming database we're gonna talk about what exactly this means in just a second but once you have the name filled out and the application name you're gonna want to go ahead and hit create this will start a new project for you and you'll notice that it generates a bunch of files for you we're going to talk about each of these files in order so the first file right here is manage py and you don't need to actually look inside of this file but manage that py allows us to do a bunch of important functions with our Django website we're going to use it at a couple of different points throughout the series you basically just access it directly Python manage py and whatever you want to do and it'll let you do things like migrate the database or create a super user account or launch a shell so on and so forth next is the templates folder this is where all of your HTML templates will go when we get to that part where we're actually writing all of the different pages those HTML files will go in there now the programming database folder is the project folder this is the programming database project and there are three important files in here settings URLs and WSGI if you take a look inside of settings this is essentially all of the settings for your project we aren't going to touch anything in here right now but we will come here and a few times throughout the series to tweak a couple of things but this essentially controls all of the settings for your project if you go to URLs this is the URL mapping or a URL resolver part that was the first step in that diagram that we looked at so there's a URL pattern built in if you try to go to an admin page it will take you to the admin site we're gonna talk about that a lot later on in the episode but this is where we will define the URL mappings so if they go to slash it'll take them to the home page if they go to slash user slash ID it'll take them to that user ID page that's where all of that will go and WSGI this we're going to use when we deploy our website so this WSGI file is what will get run by apache or engines or gonna corn goona corn i'm not sure what it's called but one of those services that actually runs your django application in production so we're gonna get to that last thing in the series and it's not a file that you're gonna want to edit at any point over here is our app the difference between an app and a project is that one project can have multiple apps and one app can belong to multiple projects now for most small to medium sized projects you're only going to have one project in one app so the distinction really isn't important the only thing that does matter is that inside of settings your app is listed under installed apps so as you can see the name is pdb underscore app and it's listed there if you set it up the way that I did with with the Django PyCharm start then it will automatically do that for you if you take a look at each of these files we can start with admin admin is where you can register all of your models to show up on the admin site we're going to talk about that later on apps basically just specifies information about your particular app not really much you're going to want to do there now models is where you actually define all of your models that was the data like for example the user so each model will be a class that will exist inside of this models file so basically this file will have all of the different models all the different sets of data that you will need to store tests you can use for testing but we're not really going cover that at least not until much later and then the last file here is views each view will just be a function and essentially the function will be in charge of loading in the template loading in all of the data from the models sticking the data from the models into the template and then returning an HTTP response that's basically all of the files here if we want to test this you'll notice that a run configuration has already been set up for us and if we hit run you will see that it starts up and if we click here to take a look you'll see it says it worked congratulations on your first Django powered page so hopefully when you run you should see this and if you do it means that you're ready to move on and actually start working on your website so that's all for this video that is the structure of a django project as we work through the series we're going to be filling in all of these different files with different things that we need to make our website work so as always subscribe if you want to see more like this video if you enjoyed it and continue on to the next video to learn more django bye for now
Info
Channel: Noah Rubin
Views: 10,015
Rating: undefined out of 5
Keywords: django, web, framework, python, python2, python3, flask, backend, frontend, html, css, javascript, model, view, controller, mvc
Id: HDRxriLLFS0
Channel Id: undefined
Length: 7min 50sec (470 seconds)
Published: Sun Mar 19 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.