Welcome back, everyone, to this lecture, we're going to be creating our first Django project.
Well, we're going to do is explore how to launch the most basic project possible with Django and project
you can think of in Django terms as just your overall web application or website.
Luckily for us, this is done easily at the command prompt.
With the Django Dash admin tool, this Django Dash admin command line tool was automatically installed
when you pip installed Django or installed that Django.
Something to keep in mind, though, is that we're going to be running these commands at the command
line.
So if you installed Django in a virtual environment, you're going to want to remember to activate that
virtual environment first.
OK.
So what do Django Armenta allows us to do is create a set of subdirectories and files for us with a
special command.
So what we're going to end up doing is at the command prompt, we're going to navigate to our desired
location of where we want to work on this project and then type Jango Dash Admin Start Project and then
the name of your website.
So Django admin, that's that special command line capability installed by Django.
And then there's many sub commands that can be called off of Django Dash admin.
And typically, the first sub command that you're gonna end up calling throughout the lifecycle of a
project is the Start Project Command.
So this is the sub command to create a new project directory, and it also automatically creates a set
of directories and files used in most Django projects.
And then this third term is what is up to you.
What do you actually want to choose for the name of your website so you can just call it something like
my underscore site, et cetera?
Something to keep in mind, though, try to use common sense as far as choosing a good name for your
website or Django project.
You probably don't want to call this project something like Django underscore admin.
Otherwise, I would get extremely confusing as far as what Django Admin is actually referring to here.
So just use common sense and try to avoid the actual term Django inside this website name.
So we go to the command prompt and then we run this particular line of code, and that ends up creating
the following set of directories or files and folders for us.
So you'll get something that looks like this.
It's going to see my site as a top level directory and then my site again and then manage that pie.
And keep in mind my site here, that's again, something you can change.
That's the custom name you choose.
So you have this outer my site and this is the root directory.
It's just a container for your project.
Keep in mind, this name doesn't technically matter to Django, so you can rename this top level project
folder or anything you want.
So you could rename this very top level directory like homework or practice, etc. Django won't complain
because it doesn't really care that that matches the project name.
Then what it also creates is directly underneath this top level root directory container is managed.
Stop Pi manage that PI is actually this python file for a bunch of command line utilities that lets
you interact with the Django project in various ways.
And we're gonna be talking a lot more about Django Admin and manage that pie.
They actually have some overlap and capabilities.
They're going to see us throughout the course.
Run different commands off.
Manage that pie.
You can think of it as its namesake as just the way to overall manage your project.
And then let's move on to this sub directory that is also created called my site.
So that's a folder.
And when you open this folder, what you're going to end up getting is a bunch of that py files within
it.
So the first one is the in it that py file, as we already know from modules and then Python.
This is just an empty file that tells Python that, hey, this directory should be considered a Python
package.
Next, we have settings that pie.
This is a settings and configuration file that we can edit for the settings that are going to be across
the entire Django project.
Later on, we'll talk about editing settings for specific tasks in our projects.
Then we have the URLs that pie.
What's nice about this is this is essentially acting as we're we're going to point the views through
our website so you can think of this almost like a table of contents for the Django powered site.
You just say, Hey, this this view to this URL.
Again, we're going to talk a lot more about views and URLs later on.
And then you have an SGI that PI file.
That's an entry point for a SGI compatible web servers to serve your project.
We'll talk about that and what that actually means in more detail later on.
And then similarly, there is a SGI, which is an entry point for WSI compatible web servers to serve
your project.
We'll talk about those two and a lot more detail later on.
But just think about this as being automatically created for you, and you'll typically have all these
files in a project when you're just starting off.
And then later on, we're going to edit these work with them and see how to actually use them.
For right now, though, let's go ahead and practice creating this, and then we're actually going to
be able to run the server through the manage that file and see our Django project live.
So we're going to create a very first Django project.
Let's head over to Visual Studio code.
All right, here I have a Visual Studio code recall that I have this top level folder called Django
Lectures, et cetera.
Go ahead and navigate using your command, prompt or terminal here to wherever you actually want to
work with this particular project.
So if you want to, you could use code to change directory and then start to go back up a directory.
If you want it to just work with all these files on your desktop, or you could say CD and then start
typing in the name of wherever you want it to work, such as Django lectures on my desktop and then
change directories back down into wherever you happen to be working.
So it's really up to you.
Sometimes it's easier to change where you are here in the Explorer or say file.
And then if you go file open folder, you could open a folder somewhere else completely different on
your computer and then relaunch the terminal there in order to get the terminal to connect.
So keep that in mind.
Lots of different ways you can do this.
I'll go ahead and launch my project inside Django lectures.
The next thing you want to be aware of is if you're happening to be using a virtual environment, are
going to want to activate the virtual environment right now before you start calling these commands,
especially if Django's only installed in your virtual environment.
I was going to do this on my top level installation of Python, and then we're going to do here is actually
start the project.
So I say Django, that admin space and then we say Start Project.
Space and then whatever you want to actually call that project.
So let's call this project my site or my website, whatever you want to actually call it, enter and
then nothing was actually going to be reported for you at the terminal.
But if you come back up here, you'll notice we have those directories I mentioned.
We have my site, my site, we have the files already talked about settings, up pi, et cetera.
You can see the URLs that PI, this is going to connect things, et cetera.
And then you have managed that pi and all that jazz.
And we're going to talk about the details of these files later on in the course.
But you'll notice URLs actually already has things set up, such as the admin site, which is kind of
interesting.
The path is admin, so we'll talk about that later on.
You can see there is a ton of functionality already included inside of Django, so this helps really
speed up your development when you can launch something like this with just a single line of code.
Now again, we don't understand every single file does yet, but as you go and progress throughout this
course, you're going to see the power of Django and its ability to quickly spin up a project like this.
For now, we're going to use manage that PI and manage that.
PI has a bunch of different command line arguments that we can actually use that are called from Django,
and the first we're going to be doing is the run server command.
So we'll come back down here to our terminal and I'm going to say Python.
I'm going to call.
Actually, we have to make sure we're in the same directory.
So keep in mind right now I'm enjoying your lectures, but I actually want to be in the same directory
as managed up pie.
So I want to see the.
And then go to my site, and if you want to confirm whether or not the managed file is there, you can
say else if you are on Mac OS or Linux or if you're on Windows, you say the air to show the directory
and essentially we want to do is confirm that managed up high is there.
So you can see it's a little confusing.
They you have to my site folders here or my site directories, so keep that in mind.
It can be kind of confusing and sometimes you think you're at the top level directory or the root directory
when you're actually inside here and you start calling managed up high.
But it says, sorry, manage that pie doesn't exist.
Just keep that in mind.
You have these two directories that have the same name.
OK.
So let me clear that I'll skip seals since I'm on windows.
It's just the word clear if you are on Mac OS or Linux, so type class.
OK, now I know.
Manage that pies there.
I'm going to say Python.
Managed up high note that I'm not just calling Python and then hitting enter, otherwise that just starts
Python.
So I'm going to quit that again.
That's another really common beginner mistake.
So I'm gonna quit that.
Let's go ahead and clear that again, I'm going to say Python, and I'm actually going to run managed
up by it.
So, say managed that pie, and then there's a command line argument they can pass in to manage that
pie.
And that is run server all one word.
And this is actually going to essentially launch the website.
It's going to complain that you have some unemployed migrations.
Don't worry about that right now.
Let's do more with things like authorization, administration sessions, cetera.
Well, you should notice is it said, Hey, I'm starting the development server right here.
And notice it has an actual what looks like a website address.
So we're going to control.
Click this in order to follow the link.
Well, you should be careful of is do not use control C. I'll show you what happens if you lose control.
C. So being a mistake, I see all the time student highlights this.
They say control c and either they get something here or hey, some key bindings, don't go to the terminal
by default.
It's actually kind of a nice feature, but in other like a Mac OS terminals or different IDs that actually
kills the server.
So Control C is super common for killing the server.
So just keep that in mind, you want to make sure that you come back to this command line.
And he didn't actually say Control C to copy this away.
But let's go to this.
I'm going to control.
Click the follow this link, and when you follow this link, you should get some sort of application
or page that says, Hey, the install works successfully.
Keep in mind, each version of Django usually has a different picture and a different look.
So by the time you're running this in Django, for which I'm right now showing you for three point two
sons, four isn't out at the time of me filming this.
Keep in mind, it's maybe a slightly different picture.
So other than that, you should see some sort of OK, everything's working page.
The last thing I want to mention is we are right now running this at the default port, which is 8000.
But as a second argument, you can actually tell it to run at a different port.
So going to come back to jingle lectures.
Notice that you start getting all these get requests information.
We'll talk a lot more about that later on.
But what I'm going to do here is do control C to actually kill this say class here, and I'm going to
say python managed pie.
Run server, and then let's say, instead of the 8000 port, I wanted to run it at 88 port because maybe
something else on my computer is running 8000 port.
You just type that in as a secondary command, 80 80.
Then you go ahead and hit.
Enter here and you'll notice it says now it's running at one two seven zero zero one 80 80 and you can
control.
Click to follow that link.
OK.
Again, we'll talk about all these kind of warnings etc migrations, but for right now, you have successfully
run your first Durango project.
We're going to do next.
Let's talk about the difference between projects and Django apps.
And there's a little bit of confusing terminology there.
So let's take a lecture to address that coming up next.
Thanks.
I'll see you there.