Starting a Django App
00:00 With your Django project in place, you’re now ready to start a Django app.
00:05 Now remember, when creating a Django project you’ve got this basic project structure with a management app. And what are you going to do now in this lesson is run the command to create one of these blue squares, a Django app. And also, like I mentioned earlier, you can make more of those inside of your Django project and they’re all going to work with the same command.
00:26
That command is the following: python3 manage.py startapp
and then the name of the app. You can see that here you’re using the manage.py
file that you created when creating your Django project and you’re using this one to run something called startapp
and then passing it as an argument the name of the app that you want to create. In this example, I’m going to use, as the name for the app, I’m going to say example
.
00:56
So the command would look like this: python3 manage.py startapp example
.
01:02 So, let me head over to VS Code and let’s execute this.
01:07
You see that here I have the project structure that got created when running django-admin startproject .
with the dot at the end. So, manage.py
and the management app setup/
, they sit directly in the current working directory that I’m in.
01:23
If you didn’t run it with the dot, then you will first have to navigate inside of your project folder before you can execute the manage.py
file. So, let’s write this command.
01:35
It goes python3 manage.py startapp
and then the name of the app, let’s say this is going to be example
.
01:45 When I execute this command, here on the side, you can see a new folder pops up and this is a Django app that has a structure and a couple of files inside of it.
01:57 That is always going to be the same for whatever app you’re going to start moving forward. It’s going to take the name that you pass and then create this selection of beautiful and useful Django files that you will work with when you build your project. Now I want to show you that I can make more than one of these and that it’s going to have the same structure, so if I create a second app in my Django project, it pops up again on the same level as the management app and the other app that I created before, and both of these have the same content.
02:31
They have a migrations/
folder and a couple of files that are all relatively empty. They have some imports that Django already shows you that you’re going to need.
02:40 Here’s a bit of setup already done for you that just relates to the name that you gave. But most of it is just a single import and then a comment that gives you a hint of what you’re supposed to do in here. Now, these comments—this one doesn’t say very much, if you don’t know what a model is it’s not going to be that helpful—but keep in mind that there’s a lot of nice tips that already come with Django.
03:07 And I actually encourage you to go and explore this folder structure some more. Go and create a couple of apps, delete them, look around inside, figure out what you can find out of what these files are probably meant for.
03:21
Maybe you have some experience with Django already, and otherwise you can learn a lot by just poking around a bit. For example, going to the settings.py
file in your management app, you can see that there’s a lot, a lot of comments that give you information about what the different settings do. So just read up on this a bit, spend some time on it before moving forward, because at this point you’re pretty much done with your setup and now you’re ready to start implementing your own functionality that you need.
03:50 So as a quick recap, what you did here is you started a Django app, so beginning with a Django project structure and a management app that you created in the previous lesson, you now made this blue square a Django app, and you can make more of those. But essentially, at the point when you have your Django project with the management app and one additional app, you are at the state of where you’re ready to start working on the individual functionality of your Django web development project.
04:23 Okay! In the upcoming lesson, I want to walk you over all the different commands that you went through to get to this point where you’re ready to head out into the world by yourself.
04:35 We’re going to walk through all of those steps and you can also use this video as a little command reference if you want to refresh the different steps and the related commands that you need for them. See you in the next lesson!
Become a Member to join the conversation.