Setting Up a Project in the Current Directory
00:00 In this lesson, you will learn about an alternative for setting up a Django project, which is very similar but there’s going to be a tiny change that makes your directory structure a little different.
00:11
The tiny change is literally just adding a dot (.
) at the end of the command. Before, you ran the command django-admin startproject
, gave the project name—in our case, this was setup
—and that was it, but now if you were to add a dot at the end, just a tiny dot, this is going to create a different directory structure.
00:31 So, this is easy to miss. Take care if you look online and you might follow some Django tutorials, some of them use this dot. And now, in this lesson, you will learn what this really does.
00:44
But let’s take a step back and just think about what does this dot actually mean. So by now, in this course alone, you’ve encountered the dot twice. The first time, just now, you saw it when running django-admin startproject <projectname>
and then the dot to create a different directory structure, slightly.
01:04
And the previous time that you encountered it was when setting up your virtual environment, at least on a Unix system. And you ran this by saying python3 -m venv
and then ./
and then .venv
.
01:19 Now, not to be too confusing, this dot here means something else—this denotes a hidden directory—but this dot with the slash is the same as this dot. In Unix systems, this just means it refers to the current directory.
01:35
So here, you’re saying inside of the current directory—and you see it by ending with this slash—you want to create a new folder called .venv
. And same in this django-admin
command, startproject
,
01:51 you use the dot to denote the current directory with which you’re saying “Use the directory you’re already in as the Django project folder.” So you could also add a slash here at the end just to kind of, like, signify that this is actually a directory that you’re talking about, but you don’t have to put the slash and it makes it kind of… Usually, if you see it online, you won’t see it. All right, so this is what the dot does.
02:16
It denotes the current directory. Now let’s actually run the command and see the difference in the folder structure that it creates. Back over here in VS Code—and we still have this setup/
folder, this structure that you created before—I will remove this just to show you the difference.
02:39
And then use the same command that you used before, django-admin startproject setup
, but then I will add a dot here at the end.
02:48
When I execute this command, you can see something similar happened to before, you got a setup/
folder, but you will notice that the manage.py
file now actually sits directly in your current working directory. And the setup/
folder is the management app.
03:04 So the higher-level project folder didn’t get created, otherwise, the structure is exactly the same. Let’s look at this again in a schematic.
03:15
So when running django-admin startproject setup .
with a dot, then what gets created is the management app—this is the red square in the graphic that you saw before—and then the manage.py
command center of your app, and they get created directly inside of your current working directory, rather than for Django to create a new project folder of the same name as your management app.
03:43 And that’s the difference with the dot. You can here see that what gets created if you use it without the dot and this is what gets created when you use the dot.
03:54
So now you learned two different ways of starting your Django project. You can do it either with django-admin startproject
and then your project name, or if you want to skip the creation of the project folder, then you use the same command but you add a dot (.
) at the end.
04:10 That’s all about starting a Django project. Next up, you’re getting ready to start a Django app. See you there!
Martin Breuss RP Team on June 14, 2021
Glad it was helpful @Jack! It confused me as well when I first got started with Django : )
Paulo Vital on June 18, 2021
Which of the commands is the most recommended to structure a new project?
Martin Breuss RP Team on June 18, 2021
Hi @Paulo Vital. There’s no strict recommendation for this. Both commands do essentially the same, the only difference is whether you’re creating one additional folder for nesting your project, or if you declar the folder you’re already in as the project folder.
If you want to follow the official Django documentation, you’ll see that they use the startproject
command without the dot (.
) at the end.
Become a Member to join the conversation.
Jack on June 12, 2021
OMG, this “slimmer structure” just resolved my deepest confusion in learning Django! Just like that! What a great demonstration!